Sometimes I am confused with 'liftA2' and 'converge' functions.

Main difference between those is that:

  liftA2 takes applicative functor as second and third arguements, for example, array

  converge takes functions as second and third arguements

// liftA2 :: Applicative m => (a -> b -> c) -> m a -> m b -> m c
// converge :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
// liftA2 :: Applicative m => (a -> b -> c) -> m a -> m b -> m c
// converge :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
const { option, curry, liftA2, converge } = require("crocks");
const { getState } = require("../../helper"); // getColors :: () -> State AppState [String]
const getColors = () => getState("colors").map(option([])); // getShapes :: () -> State AppState [String]
const getShapes = () => getState("shapes").map(option([])); // buildCard :: String -> String -> Card
const buildCard = curry((color, shape) => ({
id: `${color}-${shape}`,
color,
shape
})); // buildCards :: [String] -> [String] -> [Card]
const buildCards = liftA2(buildCard); // generateCards :: () -> State AppState [ Card ]
const generateCards = converge(liftA2(buildCards), getColors, getShapes); module.exports = {
generateCards
};

[Functional Programming] liftA2 and converge的更多相关文章

  1. Beginning Scala study note(4) Functional Programming in Scala

    1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...

  2. Functional Programming without Lambda - Part 2 Lifting, Functor, Monad

    Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...

  3. Functional Programming without Lambda - Part 1 Functional Composition

    Functions in Java Prior to the introduction of Lambda Expressions feature in version 8, Java had lon ...

  4. a primary example for Functional programming in javascript

    background In pursuit of a real-world application, let’s say we need an e-commerce web applicationfo ...

  5. Functional programming

    In computer science, functional programming is a programming paradigm, a style of building the struc ...

  6. Java 中的函数式编程(Functional Programming):Lambda 初识

    Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...

  7. Functional programming idiom

    A functional programming function is like a mathematical function, which produces an output that typ ...

  8. 关于函数式编程(Functional Programming)

    初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...

  9. Functional Programming 资料收集

    书籍: Functional Programming for Java Developers SICP(Structure and Interpretation of Computer Program ...

随机推荐

  1. Echarts API说明文档

    theme = {        // 全图默认背景        // backgroundColor: 'rgba(0,0,0,0)',                // 默认色板        ...

  2. 1255: 打怪升级(Java)

    WUSTOJ 1255: 打怪升级 Description 对于多数RPG游戏来说,除了剧情就是打怪升级.本题的任务是用最短的时间取得所有战斗的胜利.这些战斗必须按照特定的顺序进行,每打赢一场,都可能 ...

  3. jira索引失败

    """ # 参考:http://www.mamicode.com/info-detail-2369087.html jira断电重启后索引失败, 解决方法: 关闭jira ...

  4. sonar+Jenkins 构建代码质量自动化分析平台

    1.Sonar 介绍 Sonar 是一个用于管理代码质量的开源工具,可以分析代码中的bug和漏洞以及Code Smells,支持20多种编程语言的检测,如java,c/c++,python,php等语 ...

  5. hdu 1698 线段数的区间更新 以及延迟更新

    先说说区间更新和单点更新的区别 主要的区别是搜索的过程 前者需要确定一个区间 后者就是一个点就好了 贴上两者代码 void updata(int i)//单点更新 { int l=stu[i].l; ...

  6. jvm的内存区域介绍

    什么是jvm? JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的 ...

  7. C# 高低位获取

    ushort Tbed = 2255; byte gao = (byte)(Tbed >> 8); byte di = (byte)(Tbed & 0xff); ushort a ...

  8. Java Web 深入分析(6) Tomcat

    tomcat是什么:汤姆猫?Javaweb服务器? Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache ...

  9. java小工具:通过URL连接爬取资源(图片)

    java语言编写一个简单爬取网站图片工具,实现简单: 通过 java.net.HttpURLConnection 获取一个URL连接 HttpURLConnection 连接成功返回一个java.io ...

  10. 报错/Warning: You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored

    这个报错在以下情形会出现 第一种 <Switch> <Route exact path="/home/index" component={HomeIndex} / ...