[Ramda] Convert Object Methods into Composable Functions with Ramda
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Ramda] Convert Object Methods into Composable Functions with Ramda相关的知识,希望对你有一定的参考价值。
In this lesson, we‘ll look at how we can use Ramda‘s invoker
and constructN
functions to take methods of an object and turn them into reusable utility functions that are curried and accept their object as the last argument. We‘ll convert a dot-chained string of jQuery methods and create a composed function that can be applied to multiple elements.
const {invoker, compose, constructN} = R // $(‘#sample‘) // .animate({left:‘250px‘}) // .animate({left:‘10px‘}) // .slideUp() const animate = invoker(1, ‘animate‘) const slide = invoker(0, ‘slideUp‘) const jq = constructN(1, $) const animateDiv = compose( slide, animate({left:‘10px‘}), animate({left:‘250px‘}), jq ) animateDiv(‘#sample‘) animateDiv(‘#sample2‘)
以上是关于[Ramda] Convert Object Methods into Composable Functions with Ramda的主要内容,如果未能解决你的问题,请参考以下文章
[Ramda] Declaratively Map Predicates to Object Properties Using Ramda where
[Ramda] Pluck & Props: Get the prop(s) from object array
[Ramda] Basic Curry with Ramda