Author: Chris Warburton <chriswarbo@gmail.com>
Date: Thu Aug 21 12:58:35 PM UTC 2014
Parent: 7ae24f3a9225297e6c951a82d4be99e516ddaf1d
Log message:
Implement []
1: diff --git a/.gitignore b/.gitignore 2: new file mode 100644 3: index 0000000..0d20b64 4: --- /dev/null 5: +++ b/.gitignore 6: @@ -0,0 +1 @@ 7: +*.pyc 8: diff --git a/plumb.py b/plumb.py 9: index d3b688f..cf9d145 100644 10: --- a/plumb.py 11: +++ b/plumb.py 12: @@ -15,8 +15,12 @@ def build(): 13: def chain(env, calls): 14: return reduce(call(env), calls, lambda x: x) 15: 16: - def plumb(env, expr): 17: - return curry(lambda arg: chain([arg] + env, expr)) 18: + def plumb_(env, expr, arg): 19: + if len(expr) is 0: 20: + return arg 21: + return chain([arg] + env, expr) 22: + 23: + plumb = curry(plumb_) 24: 25: return curry(lambda expr: plumb([], expr)) 26: 27: diff --git a/test.py b/test.py 28: index f1034ba..31af281 100644 29: --- a/test.py 30: +++ b/test.py 31: @@ -8,46 +8,65 @@ def failures(ts): 32: results = {n: test(t) for n, t in ts.iteritems()} 33: return {n: (l, r) for n, (l, r) in results.iteritems() if l != r} 34: 35: +def show(ts): 36: + if len(ts) > 0: 37: + print ts 38: + return 39: + print "Passed" 40: + 41: from core import * 42: 43: -core_fails = failures({ 44: +core_fails = show(failures({ 45: 'currying curries': lambda a, b: ( 46: curry(lambda x, y: x + y)(a)(b), 47: a + b), 48: + 49: 'curried functions still callable as normal': lambda a, b: ( 50: curry(lambda x, y: x + y)(a, b), 51: a + b), 52: + 53: 'currying uncurries': lambda a, b, c: ( 54: curry(lambda x, y: lambda z: x + y + z)(a, b, c), 55: a + b + c), 56: + 57: 'can curry types': lambda a: ( 58: curry(str)(a), 59: str(a)), 60: + 61: 'curry passes on keywords': lambda a, b: ( 62: curry(lambda x, **kwargs: map(str, kwargs.iteritems()), 63: foo=a)(b), 64: [str(('foo', a))]), 65: + 66: 'curry ignores defaults': lambda a, b, c: ( 67: curry(lambda x, y=a: x + y, b, c), 68: b + c) 69: -}) 70: +})) 71: 72: from plumb import * 73: 74: -plumb_fails = failures({ 75: +plumb_fails = show(failures({ 76: 'plumb thunks': lambda a, b: ( 77: plumb([str(a)])(b), 78: str(a)), 79: + 80: 'plumb id': lambda a: ( 81: + plumb([])(a), 82: + a), 83: + 84: + 'plumb id 2': lambda a: ( 85: plumb([0])(a), 86: a), 87: + 88: 'plumb de Bruijn': lambda a: ( 89: plumb([[1 , 0]])(str, a), 90: str(a)), 91: + 92: 'plumb curries': lambda a, b: ( 93: plumb([[[2 , 1 , 0]]])(lambda x, y: x + y, a, b), 94: a + b), 95: + 96: 'plumb uncurries': lambda a: ( 97: plumb([str , 0], a), 98: str(a)) 99: -}) 100: +}))