DEV Community

Discussion on: Converting Lodash to fp-ts

Collapse
 
patroza profile image
Patrick Roza

log(A.filter(x => x ? true : false)([0, 1, false, 2, '', 3]))
->
log(A.filter(Boolean)([0, 1, false, 2, '', 3]))
or

const compact = A.filter(Boolean)
log(compact([0, 1, false, 2, '', 3])) 
Enter fullscreen mode Exit fullscreen mode

instead of Boolean, one that also narrows the type:
function isTruthy<T>(item: T | null): item is T { return Boolean(item) }