Skip to content
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

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/content/manual/v1.7/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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

Copy link
Author

@mousetail mousetail Sep 14, 2024

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".

Copy link
Member

@wader wader Sep 16, 2024

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" 🤔

Copy link
Author

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

Copy link
Member

@wader wader Sep 16, 2024

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?

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Member

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 :)

Copy link
Author

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

Copy link
Contributor

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.

elements. `last` returns `null` instead.

examples:
- program: "[range(.)]|[first, last, nth(5)]"
input: "10"
output: ["[0,9,5]"]
- program: "[range(.)]|[[first], [last], [nth(5)]]"
input: "0"
output: ["[[],[null],[]]"]

- title: "`reduce`"
body: |
Expand Down
Loading