Last active
February 13, 2025 03:00
-
-
Save ryochin/638a475998af5d1db91e57c7e56cf8ec to your computer and use it in GitHub Desktop.
TS: filterMap using ramda.js
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
import { chain, isNotNil } from 'ramda' | |
export const filterMap = <A, B>(fn: (a: A) => B | null, list: A[]): B[] => | |
chain((x: A): B[] => { | |
const result = fn(x) | |
return isNotNil(result) ? [result] : [] | |
}, list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment