Ejemplo n.º 1
0
def format_one_exception(
        exc: Exception,
        tb_filter: Callable[[List[FrameSummary]], List[FrameSummary]]=I,
        tb_formatter: Callable[[List[str]], List[str]]=I,
        exc_formatter: Callable[[List[str]], List[str]]=I,
) -> Tuple[List[str], List[str]]:
    e_str = exc_formatter(sanitize_tb(Lists.wrap(format_exception_only(type(exc), exc))))
    tb = tb_filter(Lists.wrap(extract_tb(exc.__traceback__)))
    tb_str = tb_formatter(sanitize_tb(Lists.wrap(format_list(tb))))
    return e_str, tb_str
Ejemplo n.º 2
0
 def _getitem(self) -> None:
     f = __[1]
     a = 13
     f((1, a, 2)).should.equal(a)
     g = self.__.filter(self._ > 1)[1]
     b = 6
     g(List(4, 1, b)).should.equal(b)
     h = self._.x[0]
     h(Just(List(a))).should.equal(a)
     i = self._.x[0].length
     l = 3
     i(Just(List(Lists.range(3)))).should.equal(l)
Ejemplo n.º 3
0
 def exports(modpath: str) -> 'Either[ImportFailure, amino.list.List[Any]]':
     from amino.list import Lists
     exports = yield Either.import_name(modpath, '__all__')
     yield Lists.wrap(exports).traverse(lambda a: Either.import_name(modpath, a), Either)
Ejemplo n.º 4
0
    def fold_m(self) -> None:
        def f(z: int, a: int) -> Either[str, int]:
            return Right(z + a) if a < 5 else Left('too large')

        Lists.range(5).fold_m(Right(8))(f).should.contain(18)
        Lists.range(6).fold_m(Right(8))(f).should.be.left
Ejemplo n.º 5
0
 def __call_as_pre__(self, *a, **kw):
     a0, rest = Lists.wrap(a).detach_head.get_or_fail(
         'no arguments passed to OperatorLambda')
     return self.__call__(a0), rest
Ejemplo n.º 6
0
def sanitize_tb(tb: List[str]) -> List[str]:
    return tb.flat_map(lambda a: Lists.wrap(a.splitlines())) / (lambda a: a.rstrip())
Ejemplo n.º 7
0
    def __init__(self, b: int) -> None:
        self.b = b

    def get(self) -> int:
        return self.b

    def add(self, n: int) -> int:
        return self.b + n


class _A:

    def __init__(self, a: int) -> None:
        self.a = _B(a)

nums = Lists.wrap(_A(i) for i in range(10000))


class _BenchSpec(Spec):

    def _builtin_lambda_bench(self) -> None:
        amino_root_logger.info('')
        l: Callable = lambda a: a.a.get()
        @timed
        def for_lambda() -> None:
            [l(a) for a in nums]
        @timed
        def map_lambda() -> None:
            nums.map(l)
        @timed
        def builtin_map_lambda() -> None:
Ejemplo n.º 8
0
 def run() -> Do:
     from amino.list import Lists
     exports = yield Either.import_name(modpath, '__all__')
     yield Lists.wrap(exports).traverse(
         lambda a: Either.import_name(modpath, a), Either)
Ejemplo n.º 9
0
 def v(self) -> List[B]:
     return Lists.wrap(Dict.values(self))