Add core List combinators to the standard library - #766
Open
MohibShaikh wants to merge 3 commits into
Open
Conversation
Add map, fold, sum, all, any, find, contains, take, drop, at, zip, range to the List module, following the existing fold/recursion idiom.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds 12 core
Listcombinators to the standard library (src/fun/builtins.bend):List/map,List/fold,List/sum,List/all,List/any,List/find,List/contains,List/take,List/drop,List/at,List/zip,List/range.Why
The
Listmodule currently only exposeslength,reverse,split_once,flatten,concat, andfilter, so the everyday functional toolkit (map/fold/take/zip/…) has to be re-implemented by every user. These are the most commonly reached-for list operations.Notes
foldfor catamorphic reductions (map,fold,sum) and structuralmatch-recursion where early-exit or index tracking is needed (all,any,find,take,drop,at,zip). No imperative loops.List/sumandList/containsareu24-specialized because arithmetic/equality operators only apply to native numbers and there is no genericEq/Numinterface in the stdlib; the rest are generic over the element type.List/findandList/atreturnMaybe(T);List/atreturnsMaybe/Nonefor out-of-bounds indices.List/take/List/dropclamp gracefully whennexceeds the length;List/ziptruncates to the shorter list;List/rangeis half-open[start, end).Tests & docs
tests/golden_tests/run_file/list_combinators.bendexercising all 12 functions (including the clamp/truncation edge cases), with a recorded snapshot.docs/builtins.mdand added a CHANGELOG entry.