Last active
December 23, 2015 01:59
-
-
Save domgetter/633e37f8c136abcdaf29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map = -> f, rf, acc, elem { | |
rf[acc, f[elem]] | |
} | |
[1,2,3].reduce(0, map.curry[-> n {puts n; n}][:+.to_proc]) | |
[1,2,3].reduce(0, &-> rf, acc, elem { rf[acc, elem] }.curry[:+.to_proc]) | |
identity = -> x { x } | |
zero = -> f { -> x { x } } | |
one = -> f { -> x { f[x] } } | |
zero_tr = -> f { -> x { -> y { x[y] } } } | |
one_tr = -> f { -> x { -> y { f[x[y]] } } } # vs f[x][y],same due to function composition associativity | |
identity_transducer = -> rf { -> acc, elem { rf[acc, elem] } } | |
identity_transducer = -> rf, acc, elem { rf[acc, elem] }.curry | |
identity_transducer = -> rf { -> acc { -> elem { rf[acc, elem] } } } | |
-> f, x, y { f[x, y] } # can't really be this one | |
-> f { -> x, y { f[x, y] } } # this one in practice, this is most what we're trying to express | |
-> f { -> x { -> y { f[x, y] } } } # fully curried version, works in ruby due to partial application semantics | |
[1,2,3].reduce(0, &identity_transducer[:+.to_proc]) | |
x = -> state { -> input {new_state = incorporate[state][input]} } | |
x[x[some_state][next_element]][next_element] | |
reducer = x[some_state] | |
zero_tr = -> f { -> x { -> y { x[y] } } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment