Ramda currying: how to apply argument to multiple parameters

橙三吉。 提交于 2019-12-01 09:10:49

Another option is

chain(createList, assoc('list'))

which you can see in action on the Ramda REPL.

Update

For further explanation of how this works, I'll use the variation which will work with the next release of Ramda:

chain(assoc('list'), createList)

to show how it matches the current signature:

chain :: Chain m => (a -> m b) -> m a -> m b

Ramda treats functions as FantasyLand Monads, and therefore thus also as Chains. So to specialize the above to functions, we have

chain :: (a -> Function x b) -> Function x a -> Function x -> b

but Function x y can be written more simply as x -> y, so the above can written more simply as

chain :: (a -> x -> b) -> (x -> a) -> (x -> b)

Then you can use these (specialized) types:

createList :: OriginalData -> YourList                              (x -> a)
assoc :: String -> YourList -> OriginalData -> EnhancedData
assoc('list') :: YourList -> OriginalData -> EnhancedData           (a -> x -> b)

and hence

chain(assoc('list'), createList) :: OriginalData -> EnhancedData    (x -> b)
const f = converge(assoc('list'), [createList, identity])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!