https://github.com/atticuskuhn/typescript-lens
lens library in typescript
https://github.com/atticuskuhn/typescript-lens
fp functional-programming haskell lens
Last synced: about 2 months ago
JSON representation
lens library in typescript
- Host: GitHub
- URL: https://github.com/atticuskuhn/typescript-lens
- Owner: AtticusKuhn
- Created: 2021-11-24T01:20:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-02T05:00:10.000Z (over 4 years ago)
- Last Synced: 2025-04-12T05:58:29.198Z (about 1 year ago)
- Topics: fp, functional-programming, haskell, lens
- Language: TypeScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lens
This is a typescript library for lenses, an immutable way to access and mutate fields of datastructures. It is based on
haskell lenses [https://hackage.haskell.org/package/lens](https://hackage.haskell.org/package/lens)
# Example
Here is an example for accessing and modyfying a datastructure
```ts
type foo = {
bar: [number, number],
baz: string,
}
const myFoo: foo = {
baz: "hi",
bar: [1, 2]
}
// lensMaker function automatically generates lenses
const { bar, baz } = lensMaker()
console.log("bar is", view(bar)(myFoo))
// createLens automatically creates lenses from strings
const fooLensCreator = createLens()
const lens2 = fooLensCreator("bar.1")
console.log("the 2nd element of bar is is", view(lens2)(myFoo))
```