def unzip(self): a = 13 b = 29 l = List((a, a), (b, b), (a, a)) l1, l2 = l.unzip l1.should.equal(l2) l1.should.equal(List(a, b, a))
def eff_flat_io_empty(self): t = IO.now(List(Right(Empty()))) target = List(Right(Empty())) res = (t.effs( 4, List, Either, Maybe, Either).flat_map(lambda x: IO.now(List(Right(Just(Right(1))))))) res.value.run().should.equal(target)
def eff_flat_task(self): a, b = self._r t = Task.now(List(Right(Just(Right(a))))) target = List(Right(Just(Right(a + b)))) res = (t.effs(4, List, Either, Maybe, Either).flat_map( lambda x: Task.now(List(Right(Just(Right(x + b))))))) res.value.run().should.equal(target)
def four(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('root'), List( ViewTree.pane( SimplePane.cons('one', geometry=ViewGeometry.cons(min_size=30))), ViewTree.layout( SimpleLayout.cons('main', vertical=false), List( ViewTree.pane(SimplePane.cons('two')), ViewTree.layout( SimpleLayout.cons('sub1'), List( ViewTree.pane(SimplePane.cons('three')), ViewTree.layout( SimpleLayout.cons('sub2', vertical=false), List( ViewTree.pane(SimplePane.cons('four')), ViewTree.pane(SimplePane.cons('five')), )))))), )) data = SpecData.cons(layout) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane('one') yield ui_open_simple_pane('two') yield ui_open_simple_pane('three') yield ui_open_simple_pane('four') yield open_simple_pane('five') yield all_panes().state s, panes = self.run(go(), data) return k(panes).must(have_length(5))
def eff_map(self): a, b = self._r c = -1 t = Right(List(Just(Right(a)), Just(Left(c)), Empty())) target = Right(List(Just(Right(a + b)), Just(Left(c)), Empty())) res = t.effs(3).map(_ + b) res.value.should.equal(target)
def substitute_lnums(self) -> None: lines = List('sooo...In module imported from: asdf', 'amino/maybe.py:116:5: error: broken', 'foo/bar/__coconut__.py:22: error: nutt') return process_output(lines).should.equal( List(Map(lnum=82, text='broken', valid=1, maker_name='mypy', col=5)))
def eff_flat(self): a, b = self._r t = List(Just(Right(Just(a)))) target = List(Just(Right(Just(a + b)))) res = (t.effs( 3, Maybe, Either, Maybe).flat_map(lambda x: List(Just(Right(Just(x + b)))))) res.value.should.equal(target)
def create(worktree: Path, store: Path): List.wrap(BASE_DIRECTORIES)\ .smap(store.joinpath) %\ __.mkdir(parents=True, exist_ok=True) DiskObjectStore.init(str(store / OBJECTDIR)) repo = DulwichRepo(store, worktree) repo.refs.set_symbolic_ref(b'HEAD', _master_ref.encode()) return repo
def zip(self) -> None: a = 1 b = 2 ab = (a, b) l1 = LazyList((a, a, a, a), chunk_size=1) l2 = LazyList((b, b, b, b), chunk_size=1) l1[1] z = l1.zip(l2) z.strict.should.equal(List(ab, ab)) z.drain.should.equal(List(ab, ab, ab, ab))
def __str__(self): enum = '{}x{}, {}x{}'.format( self.latest_season, self.latest_episode, self.season, self.next_episode, ) tvid = List(self.tvdb_id) if self.tvdb_id else List() extra = (List(self.canonical_name, self.name) + tvid + List(enum, self.next_episode_date)) return '{}({})'.format(self.__class__.__name__, extra.mk_string(', '))
def read_conf(self) -> Expectation: rplugins = conf_data.map(Rplugin.from_config) successes = List( Right( DirRplugin.cons('null', '/dev/null', True, List('/some/path'))), Right(SiteRplugin.cons('plug', 'plug')), ) return ((k(rplugins[:2]) == successes) & k(rplugins.lift(2)).must(be_just(be_left)) & k(rplugins.lift(3)).must(be_just(be_left)))
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)
def one_spec() -> Do: yield NS.lift(present_venv(name)) yield update_data( rplugins=List(rplugin), venvs=List(name), active=List(active_rplugin), ready=List(name), ) yield request('update', 'flagellum') log_buffer = yield NS.inspect(lambda a: a.data.log_buffer) return k(log_buffer).must( contain(Echo.info(resources.updated_plugin(rplugin.name))))
def _candidates(self): down = ( self._no_cached_torrents_q .filter(ReleaseMonitor.downgrade_after > 0) .all() ) caching = ( self._no_cached_torrents_q .join(Torrent) .filter(Torrent.caching) .all() ) return ((List.wrap(down) / Downgrade) + (List.wrap(caching) / CheckCaching))
def _safe_search(self, query): self.log.debug( 'Search {} for {}: {}'.format(query.desc, self.requester, query.query)) try: return List.wrap(self._search(query.query)) except NoResultsError as e: self.log.debug('Error searching for torrent: {}'.format(e)) except requests.RequestException as e: self.log.warning( 'Connection failure in {} search'.format(self.search_engine)) except lxml.etree.XMLSyntaxError as e: self.log.warning('Parse error in kickass results: {}'.format(e)) return List()
def tuple_(self): x, y, z = 11, 22, 33 def mod(a): a[0][1].a = B(y) return a[0], B(x), bind(a[2]).b.set(z) b = List(B(B(0)), B(B(1)), B(B(2))) a = A(b) l1 = lens.GetAttr('b') l2 = lens.GetAttr('b')[0].GetAttr('a') l3 = lens.GetAttr('b')[2] l = lens.Tuple(l1, l2, l3) target = A(List(B(B(x)), B(B(y)), B(B(2), z))) l.modify(mod)(a).should.equal(target)
def tuple_(self): x, y, z = 11, 22, 33 def mod(a): a[0][1].a = B(y) return a[0], B(x), lens(a[2]).b.set(z) b = List(B(B(0)), B(B(1)), B(B(2))) a = A(b) l1 = lens().b l2 = lens().b[0].a l3 = lens().b[2] l = lens(a).tuple_(l1, l2, l3) target = A(List(B(B(x)), B(B(y)), B(B(2), z))) l.modify(mod).should.equal(target)
def state_task( tpe: str, path: str, tvar: List[str] = Nil, class_extra: str = '', meta_extra: str = '', ctor_extra: str = '', extra_import: List[str] = Nil, extra: str = '', ) -> CodegenTask: tpar = tvar.map(lambda a: f'{a}, ').mk_string('') tvars = tvar.map(lambda a: f'{a} = TypeVar(\'{a}\')').join_lines tpe_import = f'from {path} import {tpe}' subs = List( (r'\bF\[', f'{tpe}[{tpar}'), (r'\bF\b', tpe), ('StateT\[', f'{tpe}State[{tpar}'), ('StateT', f'{tpe}State'), ('{tpar}', tpar), ('{tvar}', tvars), ('{f_import}', tpe_import), ('{class_extra}', class_extra), ('{meta_extra}', meta_extra), ('{ctor_extra}', ctor_extra), ('{extra_import}', extra_import.join_lines), ('{extra}', extra), ('StateBase', 'StateT'), ) return CodegenTask(template_path, subs, Nil)
def filter_by_metadata(self, series=None, season=None, episode=None): filters = List( Maybe(series) / (lambda a: Release.name == a), Maybe(season) / str / (lambda a: Release.season == a), Maybe(episode) / str / (lambda a: Release.episode == a), ) return self.filter_release(*filters.join)
def add_link(self, release, url): if release.has_url(url): text = 'Release {rel} already contains link "{link}"' else: self._add_links(release, List(url)) text = 'Adding link "{link}" to release {rel}' self.log.info(text.format(link=url, rel=release.release))
def filt(entry): paths = ( List.wrap(entry.changes()) // (F(_.new.path) >> Maybe) / __.decode() ) return paths.contains(relpath)
def traverse(self, fa: List[A], f: Callable, tpe: type): monad = Applicative.fatal(tpe) def folder(z, a): return monad.map2(z.product(f(a)), lambda l, b: l.cat(b)) return fa.fold_left(monad.pure(List()))(folder)
def create_pane_from_data(window: Window, pane: Pane, dir: Path) -> Do: target_window = yield TmuxIO.from_maybe(window.id, lambda: f'{window} has no id') args = List('-t', window_id(target_window), '-d', '-P', '-c', dir) panes = yield tmux_data_cmd('split-window', args, cmd_data_pane) yield TmuxIO.from_maybe( panes.head, lambda: f'no output when creating pane in {window}')
def hackage(self, a: HsHackageRplugin) -> Do: cabal = yield N.from_io(cabal_exe()) return Subprocess(cabal, List('install', a.dep), self.rplugin.rplugin.name, 600, env=None)
def _value(self) -> A: C = Callable[[Any], Eval[Any]] def loop_compute( c: Compute[Any, Any], fs: List[C] ) -> Tuple[bool, Union[Tuple[Eval[Any], List[C]], Any]]: cc = c.start() return ((True, (cc.start(), fs.cons(c.run).cons(cc.run))) if isinstance(cc, Compute) else (True, (c.run(cc._value()), fs))) def loop_other( e: Eval[Any], fs: List[C] ) -> Tuple[bool, Union[Tuple[Eval[Any], List[C]], Any]]: return fs.detach_head.map2(lambda fh, ft: (True, (fh(e._value( )), ft))) | (False, e._value()) @tco def loop( e: Eval[Any], fs: List[C] ) -> Tuple[bool, Union[Tuple[Eval[Any], List[C]], Any]]: return (loop_compute(e, fs) if isinstance(e, Compute) else loop_other(e, fs)) return loop(self, List())
def dir_rplugin(self, rplugin: DirRplugin) -> Do: venv = yield venv_from_rplugin(rplugin) python_exe = venv.meta.python_executable bin_path = venv.meta.bin_path plugin_path = Path(rplugin.spec) / rplugin.name / '__init__.py' yield start_python_rplugin_host(rplugin, python_exe, bin_path, plugin_path, List(rplugin.spec))
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 self.__qualname__ = self.__func.__name__ self.__annotations__ = {}
def _search_kickass(self, query): from tek_utils.sharehoster import kickass search = kickass.Search(query).order(kickass.ORDER.SEED, kickass.ORDER.DESC) return List.wrap( SearchResultFactory.from_kickass(res) for res in itertools.islice(search, self._limit))
def output(): yield 'Available commands:' data = List.wrap(self.doc.items()).sort_by(_[0]) for name, (param_desc, desc) in data: yield '' yield '{} {}'.format(pad(name), param_desc) yield ' {}'.format(desc)
def parse(path: Path): with path.open() as f: try: return List.wrap(map(Map, json.loads(f.read()))) except Exception as e: self.log.error('parse error in {}: {}'.format(path, e)) return List()
def gather(self, po: ProgGather, output: Gather[A]) -> Prog[List[Either[IOException, A]]]: return Prog.pure( List( Right( GatherSubprocessResult( SubprocessResult(0, Nil, Nil, self.venv.name)))))
def collect(self) -> None: def f(a: int, n: str) -> Maybe[str]: return Just(n) if a % 2 == 0 else Nothing l: LazyList = LazyList((a, str(a)) for a in range(10)) l2 = l.collect(tupled2(f)) l2.drain.should.equal(List('0', '2', '4', '6', '8'))
def stackage(self, a: HsStackageRplugin) -> Do: stack = yield N.from_io(stack_exe()) return Subprocess(stack, List('install', a.dep), self.rplugin.rplugin.name, 600, env=None)
def _unite_word(args): first = List.wrap(args).lift(0) candidates = ( first.to_list.join if first.exists(lambda a: isinstance(a, list)) else first ) return candidates / Map // __.get('word')
def __init__( self, vim: NvimFacade, config_path: Path, plugins: List[str], bases: List[Path], type_bases: Map[Path, List[str]], initial_projects: Maybe[Projects]=Empty() ) -> None: self._config_path = config_path self._bases = bases self._type_bases = type_bases self._initial_projects = initial_projects core = 'proteome.plugins.core' ProteomeState.__init__(self, vim, List.wrap(cons(core, plugins)))
def _load_config(self) -> List[Map]: def parse(path: Path): with path.open() as f: try: return List.wrap(map(Map, json.loads(f.read()))) except Exception as e: self.log.error('parse error in {}: {}'.format(path, e)) return List() if (self.config_path.is_dir()): return List.wrap(self.config_path.glob('*.json')) \ .flat_map(parse) elif self.config_path.is_file(): return parse(self.config_path) else: return List()
def content(self): sel = self.data.selected return List.wrap(enumerate(self.data.commits[:sel + 20]))\ .flat_smap(lambda i, a: a.browse_format(i == sel))
def search(hist): all = List.wrap(takewhile(_.commit.id != id, hist)) return all.reversed
def parents(self, commit): return List.wrap(commit.parents) / self.repo.get_object
def show(self): lines = self.data.projects.show(List.wrap(self.msg.names)) header = List('Projects:') # type: List[str] return Info('\n'.join(header + lines))
def content(path: Path): return List.wrap(path.iterdir()) if path.is_dir() else List()
def _clone_repo_name(self, uri): return ( List.wrap(uri.split('/')) .lift(-1) / F(re.sub, '\.git$', '') )
def _create_mappings(self): List.wrap('jksprq').foreach(self._create_mapping) self._create_mapping('<cr>', to='%CR%')