Missing functions
michael72 opened this issue · comments
Michael Schulte commented
Just a question / poll about missing functions that are worth adding to zero_functional (if possible). These functions are probably not so easy to implement.
my ideas:
split()
(or unzip): split up a collection of tuples with n elements to n collections with single elements - the result would be a tuple of collections and not a collection of tuplescombine(a,b,c...)
(or append or union): iterate over several collections - only possible as first functiongroupBy(discr)
(similar to Scala groupBy) - collect items by a discriminator function - yielding tuples with the value of the discriminator and a list of items that were the input of the discriminator. The order is determined by the input elements order.partition(predicate: bool)
(similar to Scala partition) - which is basically groupBy with a boolean discriminator - yielding a tuple of two collections: the first where the discriminator is true, the second where the discriminator is falseremove(cond: bool)
- remove elements from the collection when the given condition is true. opposed tofilter
this changes the underlying collection.
Examples:
check(@[(1,"one"),(2, "two"), (3, "three")] --> split() == (@[1,2,3], @["one","two","three"]))
check(combine(@[1,2,3], @[4,5,6]) == @[1,2,3,4,5,6]))
# groupBy the name ending with "e"
check(@[(1,"one"),(2,"two"),(3,"three")] --> groupBy(it[1].endswith("e")) == @[(true,@[(1,"one"),(3,"three")]), (false,@[(2,"two")]))
# same with partition
check(@[(1,"one"),(2,"two"),(3,"three")] --> partition(it[1].endswith("e")) == (@[(1,"one"), (3,"three")], @[(2,"two")]))
Any suggestions?
Dmitry Atamanov commented
D's generic iteration algorithms
+1 for groupBy
(or group
) and uniq
Michael Schulte commented
... I was thinking about groupBy last weekend - not sure yet if it is feasible (or at least efficient)
uniq seems easy enough to do
Michael Schulte commented
added
- uniq
- group (instead of groupBy) -> creating a map
- partition -> creating a named tuple
- concat (instead of combine)