ulkb.util.unfoldr#
- unfoldr(f, x)[source]#
Right-unfolds x using unpacking function f.
Equivalent to:
def h(t): if f(t) is None: # no more unpacking return [t] else: return [t[0]] + h(t[1])
Used to recover values which were right-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]