我正在寻找一种将功能链接在一起的方法,类似于lodashoverSome
或flow
在 lodash 中。
这是写出的可比函数。
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})
这将是作曲版本。
const x = await _.overSome(this.getPlanGroupByUuid, this.getPlanGroupByName, this.createPlanGroup)
x({planGroups, uuid, name, user, organization})
这个想法是该函数返回带有truthy
值的第一个函数。
仅在 lodash 内这可能吗?是否有更好的带有打字稿支持的组合函数库?