[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 ...
随机推荐
- 【牛客网】Finding Hotel
[牛客网]Finding Hotel 忘记K远点对的剪枝的我有点自闭 事实上我们只要先建一棵KD树出来,维护一下所在的矩形,和子树里的最小值 每次查询的时候如果最小值比查询的值要大的话就退出 当前的答 ...
- insert 一条数据 然后拿出这条数据在数据库中生成的ID
[insert 一条数据 然后拿出这条数据在数据库中生成的ID] <insert id="insert" parameterType="management&quo ...
- 多线程(5) — JDK的并发容器
JDK提供了一些高效的并发容器,下面介绍几个 ConcurrentHashMap:这是个高效的并发HashMap,可以理解为一个线程安全的HashMap. CopyOnWriteArrayList:这 ...
- WUST 设计模式 实验一 单例模式的应用
实验一 单例模式的应用 实验目的 1.掌握单例模式(Singleton)的特点: 2.分析具体问题,使用单例模式进行设计. 实验内容和要求 很多应用项目都有配置文件,这些配置文件里面定义一些应用需要的 ...
- 跟我一起学编程—《Scratch编程》第22课:颠弹力球
1. 能够熟练绘制角色和背景造型 2. 能够熟练控制角色角度.速度等 3. 能够熟练使用变量 4. 能够熟练使用循环.选择等指令控制程序 任务描述: 1. 绘制弹力小球.托板角色,背景造型. 2. 游 ...
- SAS学习笔记26 方差分析
对于多于两组(k>2)样本均数的比较,t检验不再适用,方差分析(analysis of variance, ANOVA)则是解决上述问题的重要分析方法.方差分析由R.A.Fisher(1923) ...
- 3 webpack 4 加vue 2.0生产环境搭建
1 在前两篇笔记中已经能把开发环境弄好了,接来下构建他的生产环境 2 使用npm 安装url-loader和file-loader来支持图片和字体 npm install --save-dev url ...
- ResizeObserver - 元素resize监听API ResizeObserver
Motivation 响应式网站/Web应用程序 根据视口大小调整内容展示方式.这通常通过CSS和media查询来完成.当CSS表现不好我们会使用Javascript. 比如document.addE ...
- linux之xargs
xargs从标准输入(stdin)中读取数据进行处理 数据以空格进行分隔 可以根据参数进行一次或多次处理,默认的处理命令是/bin/echo 空行不进行处理,会被忽略 遇到命令状态为255时,xarg ...
- 使用.bat 批量将部分文件迁移到新的路径下
1.建一个11.bat ,里面写 : dir /b /s >1111.txt 保存后运行 即将所有的文件路径保存到1111.txt中 2.可以将获取的路径复制到execl中,找到自己需 ...