Last active
July 1, 2017 23:59
-
-
Save coodoo/acf4cc67753a38c87871f2009fa51809 to your computer and use it in GitHub Desktop.
Bulk monoid
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
/* | |
- Goal: | |
implmenting something like Pair(a, b) but could accommodate any amount of arguments | |
- Usage: | |
Bulk( Sum(2), Sum(3), Sum(4) ) | |
.concat(Bulk(Sum(1), Sum(1), Sum(1))) | |
Bulk( Sum(2), Sum(3), Sum(4), Sum(5) ) | |
.concat(Bulk(Sum(1), Sum(1), Sum(1), Sum(1))) | |
- Question 1: What if the arguments count aren't the same? Ex: | |
Bulk( Sum(2), Sum(3), Sum(4) ) | |
.concat(Bulk(Sum(1))) // 3 vs. 1 arguments | |
- Question 2: What if argument type doesn't match? Ex: | |
Bulk( Sum(2), Sum(3) ) | |
.concat(Bulk(All(1), First(1))) | |
*/ | |
const Bulk = (...xs) => ({ | |
xs, | |
concat: ys => Bulk(...xs.map((x, idx) => x.concat(ys.xs[idx]))), | |
bulkMap: (...fs) => Bulk(...xs.map((x, idx) => fs[idx](x))), | |
toList: _ => xs, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment