ulkb.util.unfoldl#

unfoldl(f, x)[source]#

Left-unfolds x using unpacking function f.

Equivalent to:

def g(x):
   if f(x) is None:      # no more unpacking
      return [x]
   else:
      return g(x[0]) + [x[1]]

Used to recover values which were left-folded. For example:

>>> f = (lambda t: t if isinstance(t, tuple) else None)
>>> it = unfold(f, (((1, 2), 3), 4))
>>> list(it)
[1, 2, 3, 4]