How would one implement a combinations iterator (similar to the itertools python one but type safe) that could work on strings, sets, etc. For instance:
combinations ("xyz", 2)
would yield to @['x', 'y'], @['x', 'z'], @['y', 'z'] values.
I've started with this, but don't get how user defined type classes are working or if they are in the language right now.
type
Iterable[T] = generic c
items[T](x: c): T
iterator combinations[T] (s: Iterable[T], r: int): seq[T] =
var pool: seq[T]
newSeq (pool, r)
var i = 0
for x in s:
pool[i] = x
inc i
#...