-
Notifications
You must be signed in to change notification settings - Fork 36
Exercise Answers
Speros Kokenes edited this page Mar 7, 2019
·
11 revisions
Below are some sample answers to the exercises at https://calmm-js.github.io/partial.lenses/exercises.html
const lens = "part";
const lens = [L.removable("inside"), "inside", L.removable("part"), "part"];
const valOf = key => [
L.normalize(R.sortBy(L.get("key"))),
L.find(d => d.key === key),
L.valueOr({ key }),
L.removable("val"),
"val"
];
const customEnd = L.lens(
whole => whole.start + whole.num,
(end, whole) => ({
start: whole.start,
num: end - whole.start
})
);
const end = [L.props("start", "num", "end"), L.choices("end", customEnd)];
const xs = [L.elems, L.removable("x"), "x"];
const nonObjects = L.lazy(rec => L.ifElse(
d => typeof d === "object",
[L.values, rec],
L.identity)
)
const a = L.conjugate(L.json(),L.pick({bar: ["foo", L.array(L.complement)]}));
const b = L.conjugate(L.json(), L.pick({foo: ["bar", L.array(L.complement)]}));
const iso = L.iso(L.get(a), L.get(b));