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. Python开发【杂货铺】:作用域的痛点

    1.块级作用域 想想此时运行下面的程序会有输出吗?执行会成功吗? #块级作用域 if 1 == 1: name = "lzl" print(name) for i in range ...

  2. hadoop2.7.7 分布式集群安装与配置

    环境准备 服务器四台: 系统信息 角色 hostname IP地址 Centos7.4 Mster hadoop-master-001 10.0.15.100 Centos7.4 Slave hado ...

  3. (十六)Activitivi5之内置用户组(角色)设计表以及IdentityService

    一.内置用户组(角色)设计表概念 用户和组(或者叫做角色),多对多关联,通过关联表实现 act_id_user 用户表: act_id_group 用户组表: act_id_membership 用户 ...

  4. SQL logic error no such module: fts5 解决方案

    因项目原因,需要使用SQLite的全文索引,用到了最新的fts5模块 但在咱们.net framwork中却会提示“SQL logic error no such module: fts5”:找不到f ...

  5. vs2019 product key

    Visual Studio 2019 Enterprise BF8Y8-GN2QH-T84XB-QVY3B-RC4DF     Visual Studio 2019 Professional NYWV ...

  6. nodejs连接mysql数据库,报错Client does not support authentication protocol requested by server的解决方法

    最近想要尝试nodejs连接本地数据库,往全栈方向做一个小小的尝试,于是下载了一个 MySQL8.0,发现Navicat连接不上,结果就下载了mysql自身的Workbench,继续使用. 然而,难受 ...

  7. XML-RPC-3XML-RPC 与 XML-RPC 服务器类

    http://codeigniter.org.cn/user_guide/libraries/xmlrpc.html XML-RPC 与 XML-RPC 服务器类 CodeIgniter 的 XML- ...

  8. ZROI17普及23-A.如烟题解--技巧枚举

    题目链接 因版权原因不予提供 分析 别看这是普及模拟赛,其实基本上是提高难度...像这题做NOIpT1的话也说的过去 有个很显然的暴力思路就是枚举c,a,b,时间复杂度\(O(N^3)\), 然后正解 ...

  9. Python函数知识点总结

    1.函数的定义2.如何定义一个函数以及函数语法3.函数的调用4.函数的参数(形参,实参)以及参数的传递5.函数的返回值6.变量的作用域7.匿名函数8.嵌套函数和闭包9.装饰器10.函数思维导图 1.函 ...

  10. 1.Java集合-HashMap实现原理及源码分析

    哈希表(Hash  Table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表,而HashMap的实现原理也常常 ...