Last active
August 29, 2015 14:04
-
-
Save owskio/ddad29f382fa40dc322c to your computer and use it in GitHub Desktop.
Simple non-curried lens combinators assuming a single variadic accessor.
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
var a = 1, | |
l = proxy(console.log,console), | |
data = { a: { d: 1,b: { c: 3,e: 4 } } }, | |
att = curry(function (a,o,v) { | |
//the following should also work | |
//return o[a] = v || o[a]; | |
return v ? (o[a] = v) : o[a]; | |
},2), | |
id = function (x) { return x; }, | |
a = function(fn) { | |
return function (acc,o) { | |
return fn(att('a'),acc(o)); | |
}; | |
}, | |
b = function(fn) { | |
return function (acc,o) { | |
return fn(att('b'),acc(o)); | |
}; | |
}, | |
c = function(fn) { | |
return function (acc,o) { | |
return fn(att('c'),acc(o)); | |
}; | |
}, | |
get = function () { | |
return function (acc,o) { | |
return acc(o); | |
} | |
}, | |
set = function (v) { | |
return function (acc,o) { | |
return acc(o,v); | |
}; | |
}, | |
mod = function (modifier) { | |
return function (acc,o) { | |
return acc(o,modifier(acc(o))); | |
}; | |
}, | |
add = curry(function (a,b) { | |
return a + b; | |
}), | |
composer = curry(compose,2), | |
blur = composer(mod), | |
z = 26; | |
l('-----------------------------------------------------'); | |
var result = compose(a,b,c)(blur(add)(999))(id,data); | |
l('result: ' + result); | |
l('data: ',data); | |
l('-----------------------------------------------------'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment