Skip to content

ReQL proposal: r.one #3283

Open
Open

Description

@coffeemug

A pretty common use case is to run a query that returns exactly one element, and then get that element (not a sequence with one element). Currently you could do it like this: q.nth(0).default({}), but this is somewhat annoying. I propose a term r.one that would be equivalent to this construct:

q.one() # equivalent to q.nth(0).default({})
q.one(error=True) # equivalent to q.nth(0)

Activity

  1. added this to the subsequent milestone on Nov 4, 2014
  2. mkleehammer commented on Nov 4, 2014

    @mkleehammer

    Wouldn't None be a more convenient return value for a query that you expect to either find the row or not? Particularly for languages like Javascript where if ({}) is true, unlike Python?

  3. coffeemug commented on Nov 4, 2014

    @coffeemug
    ContributorAuthor

    Ah, that's sounds reasonable, consider the proposal amended.

  4. deontologician commented on Nov 6, 2014

    @deontologician
    Contributor

    I suggest the name "first"
    On Nov 5, 2014 3:18 AM, "Slava Akhmechet" [email protected] wrote:

    Ah, that's sounds reasonable, consider the proposal amended.

    —
    Reply to this email directly or view it on GitHub
    #3283 (comment)
    .

  5. mlucy commented on Nov 6, 2014

    @mlucy
    Member

    Clearly it should be called car. (Note that in Common Lisp car of the empty list returns nil, so the analogy is actually pretty perfect.)

  6. mlucy commented on Nov 6, 2014

    @mlucy
    Member

    (Another option would be to make nth have this behavior, although I'm not sure that's a good idea.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions