Functional Module: Map/Reduce/Filter #940
Closed
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.
Motivation
Just felt the library needed this. It is super simple shouldn't really be too major.
Side Note
Also kinda shows how Zig needs lambdas of some sort most likely just the ability to declare inline functions like;
Instead of currently requiring you to predeclare that function somewhere else and use it like;
IMPORTANT
To make it easy I've made two commits; if you like the first one then please say and I'll reverse the second commit. The second commit just doesn't require types however it does make the code a bit more complicated.
FOR EXAMPLE;
The first commit would require;
mapAlloc(i32, i32, add, list, allocator);
The second just requires;
mapAlloc(add, list, allocator);
. Now while in most cases I think having explicit types helps, this is all about functional programming so I think requiring to have the types could be quite annoying.However maybe some nice @compileerrors should popup if you do things really wrong? But then again it would give you pretty good errors anyway.
Currently for example if your types mismatch it gives;
That is it looked at my array of integers being passed in and saw that the function returned a boolean and went those don't match!
IF you give a non-function, it'll tell you;
Which is real nice (integer literal cause I used '3' as a testing example).
So I think error wise it probably even gives nicer errors, then again the code is harder to understand due to a lot of builtins everywhere but it is such short snippets maybe that is acceptable?