Created
December 16, 2016 14:16
-
-
Save Willmo36/f7ce8fb6a189940fd972269352632921 to your computer and use it in GitHub Desktop.
Lens which accepts POJO or Immutable Maps
This file contains hidden or 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
//helpers | |
const getter = R.curry(function (key, obj) { | |
return Iterable.isIterable(obj) | |
? obj.get(key) : obj[key]; | |
}); | |
const setter = R.curry(function (key, val, obj) { | |
return Iterable.isIterable(obj) | |
? obj.set(key, value) : R.assoc(key, val, obj); | |
}); | |
//lens | |
const lens = (key) => R.lens(getter(key), setter(key)); | |
const active = lens("active"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment