Skip to content

Instantly share code, notes, and snippets.

@char0n
Created January 2, 2017 20:42
Show Gist options
  • Save char0n/007c37277788bd18d1871b4f77e7a53e to your computer and use it in GitHub Desktop.
Save char0n/007c37277788bd18d1871b4f77e7a53e to your computer and use it in GitHub Desktop.
const { lensPath, view, compose, pipe, defaultTo, curry } = require('ramda');
const reflectObject = {
data: {
GET: {
system: {
ntp: 3,
},
},
},
};
const dataLens = lensPath(['data']);
const GETLens = lensPath(['GET1']);
const systemLens = lensPath(['system']);
const ntpLens = lensPath(['ntp']);
const dataGetSystemNtpLens = compose(dataLens, GETLens, systemLens, ntpLens);
const viewOr = curry((defaultValue, lens, obj) => pipe(view(lens), defaultTo(defaultValue))(obj));
console.dir(viewOr(null, dataGetSystemNtpLens, reflectObject));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment