예제 #1
0
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)
예제 #2
0
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
예제 #3
0
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
예제 #4
0
def _nsImportMkdir(ns, d):
    if isNothing(d) is True:
        return

    def _nsMkdir(ns, x):
        ns.mkdir(x)

    mkdir = partial(_nsMkdir, ns)
    d | mkdir
예제 #5
0
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'
예제 #6
0
파일: init.py 프로젝트: vulogov/core.F
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
예제 #7
0
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)
예제 #8
0
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))
예제 #9
0
파일: test_DP.py 프로젝트: vulogov/core.F
def test_monad_DP_6():
    d = DP()
    d.set("/bin/add", Just(partial(a, 2)))
    assert d.get("/bin/add").value(2) == 4
예제 #10
0
def I(ns, name, fun):
    return nsSet(ns, name, partial(fun, ns))
예제 #11
0
def _nsImportLib(ns, d):
    if isNothing(d) is True:
        return
    for k, v in d:
        ns.V(k, partial(v, ns))
예제 #12
0
파일: L.py 프로젝트: vulogov/core.F
 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
예제 #13
0
파일: L.py 프로젝트: vulogov/core.F
 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)
예제 #14
0
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
예제 #15
0
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