def test_monad_Namespace_17(): def _divide(ns, x,y): return x/y d = Namespace() nsImport(d, 'coref.stdlib') d.V("/bin/divide", partial(_divide, d)) assert d.F("/bin/divide", 4, 2) == Right(2)
def test_monad_Namespace_19(): def _divide(ns, x,y): return x/y ns = Namespace() nsImport(ns, 'coref.stdlib') ns.V("/bin/divide", partial(_divide, ns)) v = ns.F("/bin/divide", 4, 0) assert len(ns.V('/sys/traceback/tb').value) == 1
def test_monad_Namespace_18(): def _divide(ns, x,y): return x/y ns = Namespace() nsImport(ns, 'coref.stdlib') ns.V("/bin/divide", partial(_divide, ns)) v = ns.F("/bin/divide", 4, 0) assert isinstance(v, Left) == True
def _nsImportMkdir(ns, d): if isNothing(d) is True: return def _nsMkdir(ns, x): ns.mkdir(x) mkdir = partial(_nsMkdir, ns) d | mkdir
def test_monad_Namespace_20(): def _divide(ns, x,y): return x/y ns = Namespace() nsImport(ns, 'coref.stdlib') ns.V("/bin/divide", partial(_divide, ns)) v = ns.F("/bin/divide", 4, 2) fv = ns.V('/sys/traceback/ftrace').value.pop() assert fv.fun == '/bin/divide'
def nsInitRegister(ns, fun, **kw): if isinstance(fun, Monad) is True: _fun = fun.value else: _fun = fun if callable(fun) is not True: return False name = kw.get('name', _fun.__name__) level = kw.get('level', 999) action = kw.get('action', 'start') _fun = partial(_fun, ns) ns.V(f"/etc/init.d/{level}/{name}/{action}", _fun) return True
def _nsImportCtx(ns, d): if isNothing(d) is True: return for k, v in d: if isinstance(v, dict) is not True: continue for k1 in d[k]: path = f"{k}/{k1}" if callable(d[k][k1]) is True: _data = partial(d[k][k1], ns, k) else: _data = d[k][k1] ns.V(path, _data)
def _nsImportInit(ns, d): if isNothing(d) is True: return if isinstance(d, Dict) is True: d = d.value for k in d: if isinstance(d[k], dict) is not True: continue for k1 in d[k]: if isinstance(d[k][k1], dict) is not True: continue for k2 in d[k][k1]: path = f"/etc/init.d/{k}/{k1}/{k2}" ns.V(path, partial(d[k][k1][k2], ns))
def test_monad_DP_6(): d = DP() d.set("/bin/add", Just(partial(a, 2))) assert d.get("/bin/add").value(2) == 4
def I(ns, name, fun): return nsSet(ns, name, partial(fun, ns))
def _nsImportLib(ns, d): if isNothing(d) is True: return for k, v in d: ns.V(k, partial(v, ns))
def map(self, mapper: Callable[[Any], Any]) -> 'L': try: ret = L.from_iterable([mapper(x) for x in self]) except TypeError: ret = L.from_iterable([partial(mapper, x) for x in self]) return ret
def apply(self, something: 'L') -> 'L': try: xs = [f(x) for f in self for x in something] except TypeError: xs = [partial(f, x) for f in self for x in something] return L.from_iterable(xs)
def test_monad_Namespace_13(): d = Namespace() d.V("/bin/doubler", partial(Doubler, d)) d.V("/home/answer", Just(21)) assert d.f("doubler")("/home/answer") == 42
def test_monad_Namespace_11(): d = Namespace() d.V("/bin/doubler", partial(Doubler, d)) d.V("/home/answer", Just(21)) f = d.V("/bin/doubler").value assert f("/home/answer") == 42