Created
April 25, 2018 22:10
-
-
Save ajcrites/f705bc60e88077984dd6036716fb8df2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Foldable<F, A> { | |
reduce: (fn: (b: A, a: A) => A, initial: A, foldable: F) => A; | |
} | |
export const getArrayFold = <R, Q extends Array<R> = Array<R>>(): Foldable<Q, R> => { | |
return { | |
reduce: (fn, initial, array) => { | |
return array.reduce(fn, initial); | |
} | |
}; | |
}; | |
getArrayFold<string>().reduce( | |
(a, b) => a + b, | |
'', | |
['hello', 'world'] | |
); | |
getArrayFold<number>().reduce( | |
(a, b) => a + b, | |
0, | |
[1, 2, 3] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment