Exemplo n.º 1
0
    def join_maybe(self, err: str) -> 'IO[B]':
        def f(a: Union[A, Maybe[B]]) -> 'IO[B]':
            return (IO.from_maybe(a, err) if isinstance(a, Maybe) else
                    IO.failed(f'`IO.join_maybe` called on {self}'))

        return self.flat_map(f,
                             fs=Just(Eval.later('join_maybe({})'.format, err)))
Exemplo n.º 2
0
 def flat_map(self,
              f: Callable[[A], 'IO[B]'],
              ts: Maybe[Eval[str]] = Nothing,
              fs: Maybe[Eval[str]] = Nothing) -> 'IO[B]':
     ts1 = ts | self.lambda_str
     fs1 = fs | Eval.later(lambda: f'flat_map({lambda_str(f)})')
     return self._flat_map(f, ts1, fs1)
Exemplo n.º 3
0
def safe_fmt(f: Callable[..., Any], a: tuple, kw: dict) -> Eval[str]:
    def s() -> str:
        try:
            return format_funcall(f, Lists.wrap(a), kw)
        except Exception as e:
            return str(f)
            log.error(str(e))

    return Eval.later(s)
Exemplo n.º 4
0
 def lambda_str(self) -> Eval[str]:
     return Eval.later(lambda: f'Pure({self.value})')
Exemplo n.º 5
0
 def and_then(self, nxt: 'IO[B]') -> 'IO[B]':
     fs = Eval.later(lambda: 'and_then({nxt.lambda_str()})')
     return self.flat_map(lambda a: nxt, fs=Just(fs))