I am looking for a way to chain functions together similar to overSome
or flow
within lodash.
This is the comparable function written out.
const e = async ({planGroups, uuid, name, user, organization}) => {
const a = this.getPlanGroupByUuid({ planGroups, uuid })
if (a) return a
const b = this.getPlanGroupByName({ planGroups, name })
if (b) return b
const c = await this.createPlanGroup({ name, user, organization })
return c
}
e({planGroups, uuid, name, user, organization})
This would be the compositional version.
const x = await _.overSome(this.getPlanGroupByUuid, this.getPlanGroupByName, this.createPlanGroup)
x({planGroups, uuid, name, user, organization})
The idea is that the function returns the first function with a truthy
value.
Is this possible within lodash alone? Is there a better compositional function library with typescript support?