Пример #1
0
 def filter(self):
     l = LazyList(range(30))
     l2 = l.filter(_ % 2 == 0)
     l2.strict.should.have.length_of(0)
     l3 = LazyList(range(30))
     l3[29]
     l4 = l3.filter(_ % 2 == 0)
     l4.strict.should.have.length_of(15)
     l4.drain.should.equal(List.wrap(range(0, 30, 2)))
Пример #2
0
 def _setup_handlers(self):
     super()._setup_handlers()
     handlers = inspect.getmembers(self.Transitions, lambda a: hasattr(a, _machine_attr))
     handler_map = (
         List.wrap(handlers)
         .smap(lambda n, f: WrappedHandler.create(self, n, self.Transitions, f))
         .map(lambda a: (a.message, a))
     )
     self._message_handlers = self._message_handlers ** handler_map
Пример #3
0
    def effs(self, fa: F, *args):
        from tryp.eff import Eff

        types = List.wrap(args)
        c = L(Eff)(fa, _, depth=_)
        with_depth = lambda d, t: c(t, depth=d)
        types_only = lambda: c(types, depth=len(types))

        def try_depth(h, t):
            return with_depth(int(h), t) if isinstance(h, int) else types_only()

        return types.detach_head.map2(try_depth) | types_only
Пример #4
0
 def __init__(
         self,
         fun: Callable[..., Any],
         name: str=None,
         nargs=None,
         min: int=None,
         max: int=None,
         **kw
 ) -> None:
     self._fun = fun
     self._argspec = inspect.getfullargspec(fun)  # type: ignore
     self._params = List.wrap(self._argspec.args)
     self._param_count = self._params.length - (
         1 if self._params.head.contains('self') else 0
     )
     self._name = Maybe(name)
     self._nargs = Maybe(try_int(nargs))
     self._min = Maybe(min)
     self._max = Maybe(max)
     self._kw = kw
Пример #5
0
 def _process_result(self, old_data: Data, result) -> TransitionResult:
     if isinstance(result, Coroutine):
         return CoroTransitionResult(data=old_data, coro=result)
     elif isinstance(result, TransitionResult):
         return result
     elif isinstance(result, self._data_type):
         return TransitionResult.empty(result)
     elif isinstance(result, Message) or not is_seq(result):
         result = List(result)
     datas, rest = List.wrap(result).split_type(self._data_type)
     strict, rest = rest.split_type(Message)
     coro, rest = rest.split(iscoroutine)
     msgs = strict + coro.map(Coroutine).map(_.pub)
     if rest:
         tpl = "invalid transition result parts in {}: {}"
         msg = tpl.format(self.name, rest)
         if tryp.development:
             raise MachineError(msg)
         else:
             self.log.error(msg)
     new_data = datas.head | old_data
     return self._create_result(new_data, msgs)
Пример #6
0
 def _setup_handlers(self):
     handlers = inspect.getmembers(self, lambda a: hasattr(a, _machine_attr))
     handler_map = List.wrap(handlers).smap(Handler.create).map(lambda a: (a.message, a))
     self._message_handlers = Map(handler_map)
Пример #7
0
def decode_list(value):
    from tryp import List
    return List.wrap(value).map(decode)
Пример #8
0
 def deep(self):
     n = int(1e4)
     l = LazyList(List.wrap(range(n)))
     l.index_of(n - 1).should.contain(n - 1)
Пример #9
0
 def set(self, value):
     super().set(value)
     glob = lambda a: a.parent.glob(a.name)
     self.value = List.wrap(self.value) / _.value // glob
Пример #10
0
 def _auto_handlers(self, cls):
     import inspect
     return List.wrap(inspect.getmembers(cls)).flat_map2(self._auto_handler)
Пример #11
0
 def __init__(self, func, *a, **kw) -> None:
     assert callable(func), 'ComplexLambda: {} is not callable'.format(func)
     self.__func = func
     self.__args = List.wrap(a)
     self.__kwargs = kw
Пример #12
0
 def __init__(self, f, stack, cause) -> None:
     self.f = f
     self.stack = List.wrap(stack)
     self.cause = cause
Пример #13
0
 def with_index(self, fa: List[A]) -> List[Tuple[int, A]]:
     return List.wrap(enumerate(fa))
Пример #14
0
 def flat_map(self, fa: List[A], f: Callable[[A], List[B]]) -> List[B]:
     return List.wrap(flatten(map(f, fa)))
Пример #15
0
 def dispatch(self, obj, rpc_args):
     args = List.wrap(rpc_args).lift(0).get_or_else(List())
     if self.check_length(args):
         return self._call_fun(obj, *args)
     else:
         return self.error(args)
Пример #16
0
 def traverse(self):
     n = 3
     l = LazyList(map(Just, range(n)))
     target = LazyList(List.wrap(range(n)))
     (l.sequence(Maybe) / _.drain).should.contain(target.drain)
Пример #17
0
 def filter(self, fa: List[A], f: Callable[[A], bool]):
     return List.wrap(filter(f, fa))
Пример #18
0
 def cmd_output(self, line: str) -> List[str]:
     return List.wrap(self.vim.command_output(line).split('\n'))
Пример #19
0
 def __call__(self, *a, **kw):
     sub_a = self.__substitute(List.wrap(a))
     return self.__func(*sub_a, **kw)
Пример #20
0
 def content(self):
     return List.wrap(self.target[:]).map(decode)
Пример #21
0
 def traverse(self):
     n = 3
     target = Just(List.wrap(range(n)))
     List.wrap(map(Just, range(n))).sequence(Maybe).should.equal(target)
Пример #22
0
 def cursor(self):
     return List.wrap(self.target.cursor)
Пример #23
0
 def _log_out(self):
     return List.wrap(self.logfile.read_text().splitlines())
Пример #24
0
 def cmd(self, cmdname, group, pat, *a, **kw):
     opts = List.wrap(a) + Map(kw).to_list.smap('{}={}'.format)
     c = 'syntax {} {} /{}/ {}'.format(cmdname, group, pat, ' '.join(opts))
     self.target.cmd(c)
Пример #25
0
Файл: eff.py Проект: tek/tryp.py
 def _map(self, f: Callable):
     g = List.wrap(range(self.depth)).fold_left(f)(lambda z, i: __.map(z))
     return g(self.value)
Пример #26
0
 def map(self):
     l = LazyList(itertools.count(), chunk_size=20)
     l2 = l.map(_ * 10)
     l2[:5].should.equal(List.wrap(range(0, 50, 10)))