Skip to content

Instantly share code, notes, and snippets.

@anthonyjoeseph
Created February 28, 2021 02:41
Show Gist options
  • Save anthonyjoeseph/1c34afc2abb2daf91a0af0054e614b62 to your computer and use it in GitHub Desktop.
Save anthonyjoeseph/1c34afc2abb2daf91a0af0054e614b62 to your computer and use it in GitHub Desktop.
mapAll function
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