Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created October 24, 2019 18:23
Show Gist options
  • Save Willmo36/20f4668218f301f2bca0499c8f1f1932 to your computer and use it in GitHub Desktop.
Save Willmo36/20f4668218f301f2bca0499c8f1f1932 to your computer and use it in GitHub Desktop.
Monocle-ts nested ?
import { Lens } from 'monocle-ts'
type Foo = {
bar?: {
baz?: number[]
}
}
const bar = Lens.fromNullableProp<Foo>()('bar', {})
const baz = Lens.fromNullableProp<Foo['bar']>()("baz", [])
const foo:Foo = {
bar: {
baz: []
},
};
const result = bar.compose(baz).get(foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment