Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created December 16, 2016 14:16
Show Gist options
  • Save Willmo36/f7ce8fb6a189940fd972269352632921 to your computer and use it in GitHub Desktop.
Save Willmo36/f7ce8fb6a189940fd972269352632921 to your computer and use it in GitHub Desktop.
Lens which accepts POJO or Immutable Maps
//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