import { curry } from './curry' ; import { Arity1 , Fn } from './types' ; const NOTHING = Symbol ( 'nothing' ) ; type NOTHING = typeof NOTHING ; type Nothing = { [ NOTHING ] : true ; } ; type Just < A > = { [ NOTHING ] : false ; value : A ; } ; type Maybe < A > = Just < A > | Nothing ; param withFn param fn returns export const withPrevious = curry ( function withPrevious < A , Args extends any [ ] > ( withFn , fn ) : Fn < Args , A > { let previous = { [ NOTHING ] : true } ; return ( ... args ) : A => { if ( ! isNothing ( previous ) ) { withFn ( previous . value ) ; } const value = fn ( ... args ) ; previous = { [ NOTHING ] : false , value } ; return value ; } ; } ) as { < A , Args extends any [ ] > ( withFn , fn ) : Fn < Args , A > ; < A > ( withFn ) : < Args extends any [ ] > ( fn : Fn < Args , A > ) => Fn < Args , A > ; } ; function isNothing < A > ( maybe ) { return maybe [ NOTHING ] ; }