Beispiel #1
0
 def _flat_map(self, f: Callable):
     ''' **f** must return the same stack type as **self.value** has.
     Iterates over the effects, sequences the inner instance
     successively to the top and joins with the outer instance.
     Example:
     List(Right(Just(1))) => List(Right(Just(List(Right(Just(5))))))
     => List(List(Right(Just(Right(Just(5))))))
     => List(Right(Just(Right(Just(5)))))
     => List(Right(Right(Just(Just(5)))))
     => List(Right(Just(Just(5))))
     => List(Right(Just(5)))
     Note: Task works only as outermost effect, as it cannot sequence
     '''
     index = List.range(self.depth + 1)
     g = index.fold_left(f)(lambda z, i: __.map(z))
     nested = g(self.value)
     def sequence_level(z, depth, tpe):
         nesting = lambda z, i: __.map(z).sequence(tpe)
         lifter = List.range(depth).fold_left(I)(nesting)
         return z // lifter
     def sequence_type(z, data):
         return L(sequence_level)(_, *data).map(z)
     h = self.all_effects.reversed.with_index.fold_left(I)(sequence_type)
     return h(nested)
Beispiel #2
0
 def sequence_level(z, depth, tpe):
     nesting = lambda z, i: __.map(z).sequence(tpe)
     lifter = List.range(depth).fold_left(I)(nesting)
     return z // lifter