You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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?
Activity
mkleehammer commentedon Nov 4, 2014
Wouldn't
Nonebe a more convenient return value for a query that you expect to either find the row or not? Particularly for languages like Javascript whereif ({})is true, unlike Python?coffeemug commentedon Nov 4, 2014
Ah, that's sounds reasonable, consider the proposal amended.
deontologician commentedon Nov 6, 2014
I suggest the name "first"
On Nov 5, 2014 3:18 AM, "Slava Akhmechet" [email protected] wrote:
mlucy commentedon Nov 6, 2014
Clearly it should be called
car. (Note that in Common Lispcarof the empty list returnsnil, so the analogy is actually pretty perfect.)mlucy commentedon Nov 6, 2014
(Another option would be to make
nthhave this behavior, although I'm not sure that's a good idea.)