Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Recursive objectLens #2

Open
raimohanska opened this issue Jul 20, 2013 · 4 comments
Open

Recursive objectLens #2

raimohanska opened this issue Jul 20, 2013 · 4 comments

Comments

@raimohanska
Copy link

Would you like a recursive objectLens, so U could

Lens.objectLens("author.firstName")(book).set("brian")

? I'll PR, if this makes sense to you...

@puffnfresh
Copy link
Member

Yes, I definitely want something like this - but not on objectLens, which should be handle all properties (yes, even silly ones with dots or unicode).

Something like this would be cool:

Lens.parse('author.0.firstName')
// non-integral become objectLens
// integral become arrayLens

And maybe another:

Lens.fromArray(['author', 0, 'firstName'])
// typeof x == 'string' become objectLens
// typeof x == 'number' become arrayLens

And they should of course have appropriate PartialLens versions.

@raimohanska
Copy link
Author

I see. You want to cover all the bases. Not the easy-going javascripter, this one :) But yeah, you're probably right.

However, from the API user's point of view, I don't like parse too much. As a user I'm don't want to think about parsing, but object fields instead. Actually I'd prefer

Lens("author.firstName")(book).set("brian")

The Lens constructor could provide a super-easy way for constructing lenses from strings and maybe function, function pairs in the spirit of the Facade pattern. Then you'd have a more strict API in the form of Lens.X, Lens.Y constructors.

@Freyert
Copy link

Freyert commented Aug 7, 2015

Out of curiosity, why the differentiation between Array and Object lenses?

@SimonRichardson
Copy link
Member

I wrote this ages ago and covers the original idea: https://github.com/SimonRichardson/fantasy-lenses/blob/master/lens.js#L103

stoeffel added a commit to stoeffel/fantasy-lenses that referenced this issue Feb 17, 2016
stoeffel added a commit to stoeffel/fantasy-lenses that referenced this issue Feb 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants