Skip to content

Instantly share code, notes, and snippets.

@coodoo
Last active July 1, 2017 23:59
Show Gist options
  • Save coodoo/acf4cc67753a38c87871f2009fa51809 to your computer and use it in GitHub Desktop.
Save coodoo/acf4cc67753a38c87871f2009fa51809 to your computer and use it in GitHub Desktop.
Bulk monoid
/*
- 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