Skip to content
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

insertAt & renameAt #183

Open
anthonyjoeseph opened this issue Apr 10, 2022 · 0 comments
Open

insertAt & renameAt #183

anthonyjoeseph opened this issue Apr 10, 2022 · 0 comments

Comments

@anthonyjoeseph
Copy link

🚀 Feature request

As discussed in gcanti/fp-ts#1460 (comment), adding insertAt and renameAt functions to all optics

Current Behavior

const user = { boss: { name: 'Anthony' } }
const newUser = { boss: { name: user.name, title: "manager" } }

const neighborhood = { house: { dog: 'Rex' } }
const newDog = { house: { cat: 'Rex' } }

Desired Behavior

const newUser = pipe(L.id<typeof user>(), L.prop('boss'), L.insertAt('title', "manager"))
// newUser: { boss: { name: string; title: string } }

const newDog = pipe(L.id<typeof neighborhood>(), L.prop('house'), L.renameAt('dog', "cat"))
// newDog: { house: { cat: string; } }

Suggested Solution

PLenses (as proposed here #59)

Who does this impact? Who is this for?

Users who want to modify the shape of their data

Describe alternatives you've considered

spectacles-ts as similar functionality, but I wanted to post here as a follow up on this comment from the fp-ts issue tracker gcanti/fp-ts#1460 (comment)

Additional context

the names 'insertAt' and 'renameAt' are analogs to existing functions in the ReadonlyRecord module of fp-ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant