Created
February 28, 2021 02:41
-
-
Save anthonyjoeseph/1c34afc2abb2daf91a0af0054e614b62 to your computer and use it in GitHub Desktop.
mapAll function
This file contains 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
const mapAll = <A, B>(vals: { | |
[K in NonNullable<keyof A>]: (val: A[K]) => B | |
}) => (a: A): { | |
[K in NonNullable<keyof A>]: B | |
} => { | |
const keys = Object.keys(a) as (NonNullable<keyof A> & string)[] | |
const mapped = fromFoldableMap( | |
S.getLastSemigroup<B>(), RA.readonlyArray | |
)( | |
keys, (key) => [key, vals[key](a[key])] | |
) | |
return mapped as { [K in NonNullable<keyof A>]: B } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment