[Functional Programming] liftA2 and converge
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的更多相关文章
- Beginning Scala study note(4) Functional Programming in Scala
1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...
- Functional Programming without Lambda - Part 2 Lifting, Functor, Monad
Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...
- 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 ...
- 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 ...
- Functional programming
In computer science, functional programming is a programming paradigm, a style of building the struc ...
- Java 中的函数式编程(Functional Programming):Lambda 初识
Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...
- Functional programming idiom
A functional programming function is like a mathematical function, which produces an output that typ ...
- 关于函数式编程(Functional Programming)
初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...
- Functional Programming 资料收集
书籍: Functional Programming for Java Developers SICP(Structure and Interpretation of Computer Program ...
随机推荐
- Centos7.0配置Hadoop2.7.0伪分布式
一.ssh免密登录 1.命令ssh-keygen. overwrite输入y一路回车 2.将生成的密钥发送到本机 ssh-copy-id localhost中间会询问是否继续输入“yes” 3.测试免 ...
- windows安装memcache并为php添加memcache扩展
第一步:安装包下载 1.4.5 版本之前用作为一个服务安装,1.4.5 版本之后用任务计划中启用一个普通进程来使用 具体内容如以下链接:http://www.runoob.com/memcached/ ...
- python学习-27 匿名函数
匿名函数 1. 语法: lanbda x:x+1 def a(x): return x+1 res = a(10) print(res) 运行结果: 11 Process finished wit ...
- adb 安装 app/apk链接不上设备和安装出现failed_install_user_restricted的解决方法
1.手机链接电脑,保持网段一致,通过ping 看是否可以ping通 2.如果可以ping通,查看telnet ip 5555 看是否可以连接 3.如果无法连接查看手机是否开启开发者模式中的debug模 ...
- Asp.Net Core 轻松学系列-1阅读指引目录
https://www.cnblogs.com/viter/p/10474091.html 目录 前言 1. 从安装到配置 2. 业务实现 3. 日志 4. 测试 5. 缓存使用 6.网络和通讯 7. ...
- xcode 更改svn地址
xcode如何更改svn地址: 1在控制台 cd进入到项目路径下 命令提示符下输入 $svn info 查看svn信息 修改svn地址 输入如下命令 $svn switch --relocate ht ...
- 0.a开始数据结构征程
决定开始从mooc和ppt上学习数据结构,......书暂时不看.在进入数据结构之前,我首先将自己以一个还未进入大山但又向往山中美景的探险者身份对数据结构的几点疑问的答案的寻找和思考写在下面. 什么是 ...
- 【多进程】php多进程编程
先看下我已经安装的php版本 PHP (cli) (built: Jul ::) ( NTS ) Copyright (c) - The PHP Group Zend Engine v3.- Zend ...
- 提高前端开发效率的N种方法
一.使用固定的html模板和css公共样式 事先把模板建好,每次需要用的时候直接拿来就行,不再需要为浏览器兼容问题考虑太多时间 这里我整理了一套,希望对大家有帮助:http://www.cnblogs ...
- 数组的新API
话不多数,直接上代码: 第一个输出1,2,3,4,5 在函数体中第一个console依次输出1,2,3,4,5 然后再将里面的内容逐个+1,所以第二个输出值为:2,3,4,5,6 但是这都不会改变原数 ...