import { any , ap , apply , memoize , of , pipe } from 'ramda' ; const bad = ( fns ) : boolean => any ( fn => typeof fn !== 'function' ) ( fns ) ; const fnsOrArray = ( fns ) : any [ ] => Array . isArray ( fns [ 0 ] ) ? fns [ 0 ] : fns . slice ( 0 , - 1 ) ; const createSelector = ( ... fns ) => ( state , props ) => { const preFns = fnsOrArray ( fns ) . map ( fn => stateAndProps => fn . apply ( null , stateAndProps ) ) ; if ( bad ( preFns ) ) { return ( ) => { throw new Error ( 'Input-selectors to be functions' ) ; } ; } const lastFn = memoize ( fns [ fns . length - 1 ] ) ; return pipe ( of , ap ( preFns ) , apply ( lastFn ) ) ( [ state , props ] ) ; } ; export { createSelector } ;