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 <bigkevmcd@gmail.com>
Make the lists first and last functions return optional optionals. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
|
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 <bigkevmcd@gmail.com>
|
/gcbrun |
Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
|
/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>: descriptionin the merge message,if applicable.