Skip to content

Instantly share code, notes, and snippets.

@ryochin
Last active February 13, 2025 03:00
Show Gist options
  • Save ryochin/638a475998af5d1db91e57c7e56cf8ec to your computer and use it in GitHub Desktop.
Save ryochin/638a475998af5d1db91e57c7e56cf8ec to your computer and use it in GitHub Desktop.
TS: filterMap using ramda.js
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