v1.8.0 - 'branch' for conditional compositions 🔀
Updates
We just introduced a new branch
combinator. Check it out in the README, you'll love it!
The branch
function makes it easy to express more complex conditions in your compositions. It accepts 1 domain function and a predicate function that should return another domain function. You can use the output of the first function to make some conditional check and decide between the next possible domain function to run. It works sequentially like pipe
.
const prelude = makeDomainFunction()(() => ({ total: 2, next: 'multiply' }))
const sum = makeDomainFunction(z.object({ total: z.number() }))(n => n + 1)
const multiply = makeDomainFunction(z.object({ total: z.number() }))(n => n * 2)
const df = branch(prelude, output => output.next === 'multiply' ? multiply : sum)
// ^? DomainFunction<number>
What's Changed
- Branch 🔀 combinator by @gustavoguichard in #82
- Bug fix 🐞: Remove prettify to avoid circular bug by @gustavoguichard in #83
Full Changelog: v1.7.1...v1.8.0