rjdbcm/Aspidites

View on GitHub
Aspidites/woma/library.wom

Summary

Maintainability
Test Coverage
`This file mainly serves as the standard library bootstrapper for the python files in`
`Aspidites/woma`

`Here are some (not at all optimal) functional interfaces for atomic arithmetic ops`

#contract
(add(x = 0 -> number; y = 0 -> number)) number
    <*> x + y

#contract
(sub(x = 0 -> number; y = 0 -> number)) number
    <*> x - y

(div(x = 0 -> number; y = 0 -> number)) number
    <*> x / y

(exp(x = 0 -> number; y = 0 -> number)) number
    <*> x ** y

(mod(x = 0 -> number; y = 0 -> number)) number
    <*> x % y

(mul(x = 0 -> number; y = 0 -> number)) number
    <*> x * y

(neg(x = 0 -> number)) number
    <*> -x

(inv(x=/0 -> bool)) *
    x = -x + 1 -> int
    <*>bool(x)

(__identity(x = /0 -> *)) *
    <*>x

(iterate(f = /0 -> Callable; x = /0 -> *)) coroutine
    i<@>iter(int, 1)
        x = f(x)
        <^>f(x)

(partition(predictor = /0 -> Callable; iterable = /0 -> Iterable)) list
    t = tee(iterable) -> tuple
    t1 = t[0] -> Iterable
    t2 = t[1] -> Iterable
    p1 = filterfalse(predictor, t1) -> Iterable
    p2 = filter(predictor, t2) -> Iterable
    <*>[p1,p2]

#ccall
#contract
(splitstr(s = '' -> str;
          sep = ' ' -> str;
          num = -1 -> int,>-2)) str
    s = s + sep -> str
    items = [] -> list
    current = '' -> str
    count = 0 -> int
    i<@>s
        current = current + i
        i == sep<?>items = items[^]current[:-1]
        i == sep<?>current = ''
        num > -1<?>count = count + 1
        <%>count == num
    <*>items