samhh / fp-ts-std

The missing pseudo-standard library for fp-ts.
https://samhh.github.io/fp-ts-std/
MIT License
207 stars 27 forks source link

Monadic memptyWhen/Unless #188

Closed samhh closed 1 year ago

samhh commented 1 year ago

Web use case: https://github.com/unsplash/unsplash-web/pull/10127#discussion_r1219062840

samhh commented 1 year ago

Rather than define this, lift the monoid and reuse memptyWhen/memptyUnless e.g.:

import * as E from "fp-ts/Either"
import * as Str from "fp-ts/string"
import { memptyUnless } from "fp-ts-std/Monoid"
import { getApplicativeMonoid } from "fp-ts/Applicative"

declare const cond: boolean
const M = getApplicativeMonoid(E.Applicative)(Str.Monoid)

memptyUnless(M)(cond)(() => etc)