You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to add Monad primitives for Enumerating over Sets/Lists. Unlike Ruby's built-in Array#combination and Array#permutation methods, these Monads would accept any Enumerable value and only execute when .each is called. This would allow building up complex nested combinatorial data structures that could be enumerated.
Enumerating Monads
Once(X)/Yield(X) - yields X, once. Basically the singleton of enumerating.
Either(X,Y) - enumerates over the elements in X, then enumerates over the elements in Y.
Maybe also add Concat(X,Y,...) that yields each value in each enumerable, in order they are given?
Toggle(X) - yields nothing and then enumerates over the values in X.
Note: could be implemented as Either(Yield(nil),X)?
Each(X) - yields every element in X.
Zip(X,Y,...) - yields each element from X, Y, etc, as if they were zipped together.
Combinatorial Monads
Choose(X, K) - enumerates over every choose of K elements in X, while respecting the order of elements.
Permute(X, R) - enumerates over every permutation of R elements in X, regardless of order.
CartesianProduct(X,Y,...) - enumerates over every combination of elements from X, Y, ..., in the order they are given.
PowerSet(X) - enumerates over every sub-set of elements within X.
Combination(X,Y,Z,...) - enumerates over every combination of elements from X, then X and Y, then Y and Z, then XY and Z.
Note: could be useful for fuzz testing where you need to test every combination of enabled features/bits.
Note: this could probably be implemented as
It would be useful to add Monad primitives for Enumerating over Sets/Lists. Unlike Ruby's built-in
Array#combination
andArray#permutation
methods, these Monads would accept anyEnumerable
value and only execute when.each
is called. This would allow building up complex nested combinatorial data structures that could be enumerated.Enumerating Monads
Once(X)
/Yield(X)
- yieldsX
, once. Basically the singleton of enumerating.Either(X,Y)
- enumerates over the elements inX
, then enumerates over the elements inY
.Maybe also add
Concat(X,Y,...)
that yields each value in each enumerable, in order they are given?Toggle(X)
- yields nothing and then enumerates over the values inX
.Note: could be implemented as
Either(Yield(nil),X)
?Each(X)
- yields every element inX
.Zip(X,Y,...)
- yields each element fromX
,Y
, etc, as if they were zipped together.Combinatorial Monads
Choose(X, K)
- enumerates over every choose ofK
elements inX
, while respecting the order of elements.Permute(X, R)
- enumerates over every permutation ofR
elements inX
, regardless of order.CartesianProduct(X,Y,...)
- enumerates over every combination of elements fromX
,Y
, ..., in the order they are given.PowerSet(X)
- enumerates over every sub-set of elements withinX
.Combination(X,Y,Z,...)
- enumerates over every combination of elements fromX
, thenX
andY
, thenY
andZ
, thenX
Y
andZ
.Note: could be useful for fuzz testing where you need to test every combination of enabled features/bits.
Note: this could probably be implemented as
These Monad enumerating primitives could be used to re-implement
Array#list_comprehension
orCartesianProduct::Mixin#cartesian_product
.The text was updated successfully, but these errors were encountered: