import { Lens , Optional , fromFoldable } from '../../src' ; import { Option } from 'fp-ts/lib/Option' ; import { array } from 'fp-ts/lib/Array' ; interface Person { name : string ; age : number ; rememberMe : boolean ; email : Option < string > ; bio ? : string ; a : { b : { c : { d : number ; } ; } ; } ; } type ConstrainedRecord = { [ K in 'a' | 'b' ] : number ; } ; type OptionPropertyNames < S > = { [ K in keyof S ] - ? : S [ K ] extends Option < any > ? K : never ; } [ keyof S ] ; type Options = OptionPropertyNames < Person > ; Lens . fromProp < Person > ( ) ( 'name' ) ; Lens . fromProp < ConstrainedRecord > ( ) ( 'a' ) ; Lens . fromProp < Person > ( ) ( [ 'foo' ] ) ; Lens . fromProps < Person > ( ) ( [ 'name' , 'age' ] ) ; const getLensFromProps = < T extends Person > ( ) : Lens < T , { name : string ; } > => Lens . fromProps < T > ( ) ( [ 'name' ] ) ; Lens . fromProps < ConstrainedRecord > ( ) ( [ 'a' , 'b' ] ) ; Lens . fromProps < Person > ( ) ( [ 'foo' ] ) ; interface FromPathBad { a : { b : { c : { [ key ] : number ; } ; d : Array < number > ; } ; } ; } Lens . fromPath < Person > ( ) ( [ 'a' , 'b' , 'c' , 'd' ] ) ; const getLensFromPath = < T extends Person > ( ) : Lens < T , number > => Lens . fromPath < T > ( ) ( [ 'a' , 'b' , 'c' , 'd' ] ) ; Lens . fromNullableProp < Person > ( ) ( 'bio' , 'foo' ) ; const getLensFromNullableProp = < T extends Person > ( ) : Lens < T , NonNullable < T [ 'bio' ] > > => Lens . fromNullableProp < T > ( ) ( 'bio' , 'foo' ) ; Optional . fromNullableProp < Person > ( ) ( 'bio' ) ; const getOptionalFromNullableProp = < T extends Person > ( ) : Optional < T , NonNullable < T [ 'bio' ] > > => Optional . fromNullableProp < T > ( ) ( 'bio' ) ; Optional . fromPath < Person > ( ) ( [ 'bio' ] ) ; Optional . fromOptionProp < Person > ( ) ( 'email' ) ; Optional . fromOptionProp < Person > ( undefined ) ; Optional . fromOptionProp < Person > ( ) ( undefined ) ; Optional . fromOptionProp < Person > ( ) ( 'name' ) ; Optional . fromOptionProp < Person > ( 'name' ) ; Optional . fromOptionProp < Person > ( ) ( 'foo' ) ; Optional . fromOptionProp < Person > ( 'foo' ) ; interface Phone { number : string ; } interface Employment { phone : Option < Phone > ; } Optional . fromOptionProp < Employment > ( ) ( 'phone' ) ; Optional . fromOptionProp < Employment > ( ) ( 'foo' ) ; interface A { type : 'A' ; } interface B { type : 'B' ; } const fold = fromFoldable ( array ) < A | B > ( ) ; const isB = ( x ) : x is B => x . type === 'B' ; const s = [ ] ; fold . find ( isB ) ( s ) ; import * as ARR from '../../src/At/ReadonlyRecord' ; import * as RS from '../../src/At/ReadonlySet' ; import { eqString } from 'fp-ts/lib/Eq' ; ARR . atReadonlyRecord < string > ( ) . at ( 'a' ) ; RS . atReadonlySet ( eqString ) . at ( 'a' ) ; import * as RA from '../../src/Index/ReadonlyArray' ; import * as RNEA from '../../src/Index/ReadonlyNonEmptyArray' ; import * as IRR from '../../src/Index/ReadonlyRecord' ; RA . indexReadonlyArray < string > ( ) . index ( 0 ) ; RNEA . indexReadonlyNonEmptyArray < string > ( ) . index ( 0 ) ; IRR . indexReadonlyRecord < string > ( ) . index ( 'a' ) ;