This file contains 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
const mapping = (f) => (reducing) => (result, input) => reducing(result, f(input)); | |
const filtering = (predicate ) => (reducing) => (result, input) => predicate(input) ? reducing(result, input) : result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not that adding extra, optional arguments is necessarily a wise thing, but I think adding the result to f(input, result) and predicate(input, result) can be interesting when using these methods. For instance, with that in place, in your filtering transducer (producer?) you can then do:
filtering((x, acc) => !~acc.indexOf(x))
And now you have a method that only allows values (or comparable objects) to be added to the result once:
reduce(filtering(dedupe)(concat), [], [1,1,1,2,6,6,7,8]);//-> [1, 2, 6, 7, 8]