testutil.py 508 Bytes
Newer Older
1 2 3
# -----------------------------------------------------------------------------
# Utils

4 5 6
def eq(x):
    return lambda y,z=x: y == z

7 8 9 10
def append(x,y):
    return x + y

def concat(xs):
krc's avatar
krc committed
11
    return reduce(append,xs,[])
12 13 14 15 16 17 18

def chop(s):
    if s[len(s)-1:] == '\n':
        return s[:len(s)-1]
    else:
        return s
    
19 20 21 22 23 24 25 26 27 28 29
def all(p,xs):
    for x in xs:
        if not p(x):
            return False
    return True

def elem(xs):
    return lambda x: x in xs

def notElem(xs):
    return lambda x: x not in xs