import{Maybe,MaybeType}from'typescript-maybe'import{compose,toUpper}from'ramda'// An example of an "unsafe" function that may return undefined or null:functionunsafeHead<T>(list: ReadonlyArray<T>): T{returnlist[0]}// Elegantly handling this unsafe function in a composition chain:typeUpperCaseHead=(list: ReadonlyArray<string>)=>Maybe<string>constotherUpperCaseHead: UpperCaseHead=compose(Maybe.map(toUpper),Maybe.of(unsafeHead),)asUpperCaseHead// Handling Maybe in a composition chain and returning a default value:typeUpperCaseHeadWithDefault=(list: ReadonlyArray<string>)=>stringconstupperCaseHeadWithDefault: UpperCaseHead=compose(Maybe.withDefault('Something didn’t quite go according to plan!'),Maybe.map(toUpper),Maybe.of(unsafeHead),)asUpperCaseHeadWithDefault