import { argumentsArray , concat } from './arrays' ; import { CurriedFunction1 , CurriedFunction2 , CurriedFunction3 } from './typedash' ; param fn param n export function curry < T1 , TResult > ( fn , n ? ) ; export function curry < T1 , T2 , TResult > ( fn , n ? ) ; export function curry < T1 , T2 , T3 , TResult > ( fn , n ? ) ; export function curry ( f , n ? ) { const argsArray = argumentsArray ( arguments ) ; if ( typeof n === 'undefined' ) { argsArray [ 1 ] = f . length ; } if ( n === argsArray . length - 2 ) { return f . apply ( undefined , argsArray . slice ( 2 ) ) ; } return function ( ) { return curry . apply ( undefined , concat ( argsArray , argumentsArray ( arguments ) ) ) ; } ; } /***
 * Function that do nothing
 */ export function noop ( ) { } param i returns { T } export function identity < T > ( i ) { return i ; } param func param wait param immediate returns { Function } export function debounce < T extends Function > ( func , wait , immediate = false ) { let timeout ; return function ( this ) { const context = this ; const args = arguments ; const later = function ( ) { timeout = null ; if ( ! immediate ) func . apply ( context , args ) ; } ; const callNow = immediate && ! timeout ; clearTimeout ( timeout ) ; timeout = setTimeout ( later , wait ) ; if ( callNow ) func . apply ( context , args ) ; } as any as T ; } param func returns { T } export function once < T extends Function > ( func ) { let called = false ; let res ; return function ( this ) { if ( ! called ) { called = true ; res = func . apply ( this , arguments ) ; } return res ; } as any as T ; } param func returns { T } export function memoize < T extends Function > ( this , func ) { const stringifyJson = JSON . stringify ; const cache = { } ; return function ( this ) : T { const hash = stringifyJson ( arguments ) ; return ( hash in cache ) ? cache [ hash ] : cache [ hash ] = func . apply ( this , arguments ) ; } as any as T ; } param schedulerFn param fn returns { T } export function delayed < T extends Function > ( this , schedulerFn , fn ) { let ticking = false ; let ctx = this ; let lastArgs = [ ] ; function handle ( ) { fn . apply ( ctx , lastArgs ) ; ticking = false ; } return function ( this , ... args ) { if ( ! ticking ) { schedulerFn ( handle ) ; } ticking = true ; lastArgs = args ; ctx = this ; } as any as T ; }