Skip to content

v2.3.0 - "Conditional `pipe`" and `mdf` alias ✂️

Compare
Choose a tag to compare
@gustavoguichard gustavoguichard released this 12 Sep 21:47
· 517 commits to main since this release
14b1e1b

New Features

  • We now export mdf alias for makeDomainFunction so your compositions will look less verbose by @gustavoguichard in #111
  • Improved branch method to act like conditional pipe 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