-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document object template of lenses #96
Comments
Yes, the documentation could be clarified here. The template for let obj = {meta: {file: "./foo.txt", base: "foo", ext: "txt"}}
L.get(L.pick({meta: ["meta", L.props("file", "ext")]}), obj) Don't have time to think this through right now, but there might be ways to allow for some form of nested version of |
Here is a kind of nested cross of let obj = {meta: {file: "./foo.txt", base: "foo", ext: "txt"}}
const nested = t => (I.isObject(t)
? L.pick(L.modify(L.values, (v, k) => [k, nested(v)], t))
: t)
L.get(nested({meta: {file: [], ext: []}}), obj) You can give it an arbitrary nested template of (plain) objects whose leaf props must be lenses. Does this seem like what you'd want and what would be a good name for this? |
Wow, recursive lensing :) I'm getting
with the last Partial.Lenses version available. Unpublished update to |
Hmm... Note that the |
BTW, thanks for opening this issue! I have to think about generalizing Here is a generalized (nested) const branch = t => I.isObject(t) ? L.branch(L.modify(L.values, branch, t)) : t
L.modify(branch({x: {a: []}, y: {b: []}}),
R.negate,
{x: {a: 1, b: 2}, y: {a: 3, b: 4}}) Here is a generalized (nested) const pick = t => I.isObject(t) ? L.pick(L.modify(L.values, pick, t)) : t
const data = {s: 1, t: 1}
const lens = pick({x: {a: "s"}, y: {b: "t"}})
R.identity({
get: L.get(lens, data),
set: L.set(lens, {x: {a: 1}, y: {b: 2}}, data)
}) Here is also the (newly proposed) generalized let obj = {meta: {file: "./foo.txt", base: "foo", ext: "txt"}}
const pickIn = t => (I.isObject(t)
? L.pick(L.modify(L.values, (v, k) => [k, pickIn(v)], t))
: t)
L.get(pickIn({meta: {file: [], ext: []}}), obj) BTW, I believe it is also time to seriously think about obsoleting |
Hi, Vesa. Sorry for not participating – mad months at work :( |
No problem. I was also just on a tightly scheduled project and finally got some time & energy to finish the initial |
Docs mention "object template of lenses" few times but it's never documented.
By trial and error I figured out that currently it supports plain values and arrays but not nested values.
For example, I want to pick
meta.file
property chain from a given object.now I want to grab both
file
andext
but notbase
keeping the original nesting:I guess it's not possible with
L.pick
(because output is a product hence a plain collection), but not sure because it's unclear what "template of lenses" is.P.S.
I'm aware of a solution:
I just wondered maybe I missed a shorter option.
The text was updated successfully, but these errors were encountered: