zero-functional / zero-functional

A library providing zero-cost chaining for functional abstractions in Nim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing functions

michael72 opened this issue · comments

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 tuples
  • combine(a,b,c...) (or append or union): iterate over several collections - only possible as first function
  • groupBy(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 false
  • remove(cond: bool) - remove elements from the collection when the given condition is true. opposed to filter 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?

D's generic iteration algorithms

+1 for groupBy (or group) and uniq

... I was thinking about groupBy last weekend - not sure yet if it is feasible (or at least efficient)
uniq seems easy enough to do 😉

added

  • uniq
  • group (instead of groupBy) -> creating a map
  • partition -> creating a named tuple
  • concat (instead of combine)