v2.3.0 - "Conditional `pipe`" and `mdf` alias ✂️
New Features
- We now export
mdf
alias formakeDomainFunction
so your compositions will look less verbose by @gustavoguichard in #111 - Improved
branch
method to act like conditionalpipe
by @gustavoguichard in #112
You can now conditionally pipe
by returning null
from a branch
, e.g:
// Check out the new `mdf` alias!
import { mdf, branch } from 'domain-functions'
import z from 'zod'
const a = mdf()(Math.random)
const b = mdf(z.number())(String)
// This function will only pipe to `b` if the output of `a` is greater than 0.5
const df = branch(a, output => output > 0.5 ? b : null)
// ^? DomainFunction<number | string>
The branch
method will keep working as always if you return other domain functions from it:
import { mdf, branch } from 'domain-functions'
const a = mdf()(Math.random)
const b = mdf()(() => 'high')
const c = mdf()(() => 'low')
const df = branch(a, output => output > 0.5 ? b : c)
// ^? DomainFunction<'high' | 'low'>
Other changes
- Expose and add JSDocs to
safeResult
to allow people to build their own combinators by @gustavoguichard in #110
Full Changelog: v2.0.0...v2.3.0