-
Notifications
You must be signed in to change notification settings - Fork 225
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
First and last #1067
First and last #1067
Conversation
This adds .first() and .last() to the list extension library which can return the first and last elements from a list. The results are returned as Optional values. Signed-off-by: Kevin McDermott <[email protected]>
Make the lists first and last functions return optional optionals. Signed-off-by: Kevin McDermott <[email protected]>
cdc2b21
to
5b59ddc
Compare
Alternative suggestion, maybe supporting the negative indexing semantics from python (-1 == last, -2 == first before last...) would be another option. But it wouldn't have the optional return value when the list is empty, which can be nice too. |
@bigkevmcd you raise an interesting point regarding optional. I think my concern with having either
I think option 1 is the cleanest since the functions would be unambiguous in their signature and encourage the use of optional values. Option 2 runs into unexpected complexity being enabled, and option 3 runs into problems where |
I remembered
|
@seirl while the use of a negative index would certainly be very clean, I'm worried that users who have implemented custom CEL lists will not be able to support the negative index without a rewrite of the expression to |
OK, I didn't realize this would be an issue, I expected that the negative index translation would happen before the custom list implementation. I've also seen people use |
Signed-off-by: Kevin McDermott <[email protected]>
6ba64f9
to
8128e0b
Compare
/gcbrun |
298d831
to
36121a5
Compare
Signed-off-by: Kevin McDermott <[email protected]>
36121a5
to
568b432
Compare
/gcbrun |
@bigkevmcd, thanks for the contribution! |
Pull Requests Guidelines
See CONTRIBUTING.md for more details about when to create
a GitHub Pull Request and when other kinds of contributions or
consultation might be more desirable.
When creating a new pull request, please fork the repo and work within a
development branch.
Commit Messages
Reviews
Merging
they have write access. Otherwise, the change will be merged by a maintainer.
closes #<issue-num>: description
in the merge message,if applicable.