Skip to content

v1.8.0 - 'branch' for conditional compositions 🔀

Compare
Choose a tag to compare
@gustavoguichard gustavoguichard released this 31 Jul 17:49
· 577 commits to main since this release
75d6679

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

Full Changelog: v1.7.1...v1.8.0