seasonedcc / composable-functions

Types and functions to make composition easy and safe
MIT License
649 stars 13 forks source link

Accept Plain functions in every combinator #155

Closed gustavoguichard closed 2 months ago

gustavoguichard commented 2 months ago

This PR introducing the tagging of composables at both type and runtime levels: fn.kind = 'composable'

This allows us to achieve: Composable<Composable<() => void>> === Composable<() => void>.

And by doing so we are now able to accept plain functions in any combinator, like so:

const add = (a: number, b: number) => a + b

// Before this PR:
const fn = collect({ add: composable(add), toString: map(composable(add), String) })

// With this PR:
const fn = collect({ add, toString: map(add, String) })

There are still 2 todos to my goal:

I think this PR as is can be merged and the remaining tasks can come later as new features.