Esempio n. 1
0
 def _lazy_method_nested(self) -> None:
     class A:
         def __init__(self, a) -> None:
             self.a = a
     values = List.range(5) / str
     s = values.mk_string(',')
     a = A(A(A(s)))
     self.L(a).a.a.a.split(',')().should.equal(values)
     self.L(A)(self._).a.a.a.split(',')(A(A(s))).should.equal(values)
Esempio n. 2
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: lambda a: a.map(z))
     nested = g(self.value)
     def sequence_level(z, depth, tpe):
         nesting = lambda z, i: lambda a: a.map(z).sequence(tpe)
         lifter = List.range(depth).fold_left(I)(nesting)
         return z // lifter
     def sequence_type(z, data):
         return lambda a: sequence_level(a, *data).map(z)
     h = self.all_effects.reversed.with_index.fold_left(I)(sequence_type)
     return h(nested)
Esempio n. 3
0
 def with_index(self):
     l = List(1, 2, 3)
     l.with_index.unzip.should.equal((List.range(3), l))
Esempio n. 4
0
 def _lazy_method(self) -> None:
     values = List.range(5) / str
     s = values.mk_string(',')
     self.L(s).split(',')().should.equal(values)
Esempio n. 5
0
 def _lambda_arg_method_ref(self) -> None:
     values = List.range(5) / str
     s = values.mk_string(',')
     l = self.L(Try)(self.__.split, ',')
     (l(s) / List.wrap).should.contain(values)
Esempio n. 6
0
 def trampoline(self) -> None:
     t = (List.range(1000).fold_left(IO.now(1))(lambda z, a: z.flat_map(IO.now, fs=Just('now'))))
     t.attempt.should.contain(1)
Esempio n. 7
0
 def sequence_level(z, depth, tpe):
     nesting = lambda z, i: lambda a: a.map(z).sequence(tpe)
     lifter = List.range(depth).fold_left(I)(nesting)
     return z // lifter