Example #1
0
 def find_map_optional(self,
                       fa: List[A],
                       tpe: Type[F],
                       f: Callable[[A], F[B]],
                       msg: CallByName = None) -> F[B]:
     a = fa.map(f).find(_.present)
     return a | (lambda: Optional.fatal(tpe).absent(call_by_name(msg)))
Example #2
0
 def flat_m(self, v):
     return call_by_name(v) if self else maybe.Empty()
Example #3
0
 def m(self, v):
     return maybe.Maybe(call_by_name(v)) if self else maybe.Empty()
Example #4
0
 def get_or_fail(self, err):
     return self.get_or_raise(Exception(call_by_name(err)))
Example #5
0
 def get_or_fail(self, err: 'CallByName') -> 'A':  # line 75
     return _coconut_tail_call(self.get_or_raise, lambda: Exception(call_by_name(err)))  # line 76
Example #6
0
 def raise_e() -> None:
     raise call_by_name(e)
Example #7
0
 def iff_m(cond: bool, a: Union['Maybe[A]',
                                Callable[[], 'Maybe[A]']]) -> 'Maybe[A]':
     return cast(Maybe, call_by_name(a)) if cond else Nothing
Example #8
0
 def c(self, t, f):
     return call_by_name(t) if self.value else call_by_name(f)
Example #9
0
 def find_map_optional(self, fa: List[A], tpe: Type[F], f: Callable[[A], F[B]], msg: CallByName=None) -> F[B]:
     for el in fa:
         found = f(el)
         if found.present:
             return found
     return Optional.fatal(tpe).absent(call_by_name(msg))
Example #10
0
 def find_map_optional(self, fa: Either[A, B], tpe: Type[F], f: Callable[[B], F[C]], msg: CallByName=None) -> F[C]:
     return fa / f | (lambda: fa.absent(call_by_name(msg)))
Example #11
0
 def cata(self, f: 'Callable[[A], B]', b: 'Union[B, Callable[[], B]]') -> 'B':  # line 55
     return (f(cast(A, self._get)) if self.is_just else call_by_name(b))  # line 56
Example #12
0
 def iff_m(cond: 'bool', a: "Union['Maybe[A]', Callable[[], 'Maybe[A]']]") -> "'Maybe[A]'":  # line 48
     return cast(Maybe, call_by_name(a)) if cond else Nothing  # line 49
Example #13
0
 def iff(cond: 'bool', a: 'Union[A, Callable[[], A]]') -> "'Maybe[A]'":  # line 43
     return cast(Maybe, Just(call_by_name(a))) if cond else Nothing  # line 44
Example #14
0
 def e(self, l, r):
     return Right(call_by_name(r)) if self else Left(call_by_name(l))
Example #15
0
 def e(self, f: A, t: B) -> Either[A, B]:
     return Right(call_by_name(t)) if self else Left(call_by_name(f))
Example #16
0
 def flat_e(self, l, r):
     return call_by_name(r) if self else Left(call_by_name(l))
Example #17
0
 def cata(self, f: Callable[[Node], A], b: Union[A, Callable[[], A]]) -> A:
     return (f(self.data)
             if isinstance(self, SubTreeValid) else call_by_name(b))
Example #18
0
 def iff(cond: bool, a: Union[A, Callable[[], A]]) -> 'Maybe[A]':
     return cast(Maybe, Just(call_by_name(a))) if cond else Nothing
Example #19
0
 def iff_l(cond: bool, a: Union[A, Callable[[], A]]) -> List[A]:
     return call_by_name(a) if cond else List()
Example #20
0
 def cata(self, f: Callable[[A], B], b: Union[B, Callable[[], B]]) -> B:
     return (f(cast(A, self._get)) if self.is_just else call_by_name(b))
Example #21
0
 async def unsafe_await_or(self, b: Union[B, Callable[[], B]]):
     return (Maybe(await (self._get)) if self.is_just  # type: ignore
             else call_by_name(b))
Example #22
0
 def get_or_fail(self, err: CallByName) -> A:
     return self.get_or_raise(lambda: Exception(call_by_name(err)))
Example #23
0
 def raise_e() -> 'None':  # line 71
     raise call_by_name(e)  # line 72