-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Docs] Clarify the behvior of first, last, and nth on empty generators #3177
base: master
Are you sure you want to change the base?
Conversation
docs/content/manual/v1.7/manual.yml
Outdated
@@ -3017,10 +3017,16 @@ sections: | |||
|
|||
The `nth(n)` function extracts the nth value of any array at `.`. | |||
|
|||
`first` and `nth` output `empty` if the generator has insufficient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if "produces no output" or "outputs no value" is better then "output empty"? seems to be what is used in other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the documentation for try
and break
also uses the phrase "output/produce empty
". In this case I think it's a bit more explicit than "outputs no value".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, i mostly want consistency but i think i personally prefer "no output" as mentioning empty feel a bit confusing, ex would we document the function empty
as producing empty
? if we want to use the word empty maybe it should not be written as a function
but instad be something like "the empty generator" or "empty output" but then i think i prefer "no output" 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the docs to say "produce no values" instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 let's see what the other maintainers think
But i do wonder what the reasoning was for last/1
to return null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One potential "fixed" last that outputs no values for an empty generator would be this:
def last(g): reduce g as $item ([0,null]; [first+1,$item])|if first>0 then last else empty end;
A lot less elagent than the current implementation though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1869. This is a bug that should be fixed in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itchyny 👍 oh long discussion, seems fascinatingly messy :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That branch is 5 years old, I doubt it will still be merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use byte code to avoid boxing like the PR even if it makes more messy.
Maybe you want to update the docs for |
@itchyny I moved the doc update to the correct section |
My understanding is that PR currently adds the text:
Of course, that is true of the current implementation, but if this behavior is to be documented in the manual, there should be a disclaimer to the effect that the behavior may change in the future. (As @itchyny recently pointed out:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm debating with myself if it's consistent that first/0
and last/0
output null
for an empty array. It makes sense because they operate on an array instead of a generator?
The existence of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding a disclaimer. Perhaps, however, it would be better if the documentation were agnostic as to whether it's a bug or not, though I would agree that simply describing the behavior as "unspecified" would be a bit silly. I believe it would be sufficient to say that currently last(empty)
evaluates to null, but that in future it is likely to evaluate to the empty stream.
I submitted a patch for the issue: #3179. |
I was confused by this behavior so thought it might be good to document it.