[Compose] 16. Apply multiple functors as arguments to a function (Applicatives)
We find a couple of DOM nodes that may or may not exist and run a calculation on the page height using applicatives.
For example we want to get the main content section size by reduce the height of header and footer, nomarlly we will do like this:
1. get the header height
2. get the footer height
3. Use screen height - header - footer.
const $ = selector =>
Either.of({selector, height: }) const getScreenSize = (screen, header, footer) => screen - (header + footer); $('header').chain(header =>
$('footer').map(footer =>
getScreenSize(, header, footer)
)
)
This happens in sequential, we can use currey function to improve the code:
const getScreenSize = screen => header => footer => screen - (header + footer);
Either.of(getScreenSize)
.ap($('header'))
.ap($('footer'))
Or we can use:
const liftA2 = (f, fx, fy) =>
fx.map(f).ap(fy)
const res = liftA2(getScreenSize(800), $('header'), $('footer'))
[Compose] 16. Apply multiple functors as arguments to a function (Applicatives)的更多相关文章
- Faiss in python and GPU报错:NotImplementedError: Wrong number or type of arguments for overloaded function 'new_GpuIndexFlatL2'.
最近在玩faiss,运行这段代码的时候报错了: res = faiss.StandardGpuResources()flat_config = 0index = faiss.GpuIndexFlatL ...
- 小程序分享报错 Cannot read property 'apply' of null;at page XXX onShareAppMessage function
Cannot read property 'apply' of null;at page XXX onShareAppMessage function 然后看了下自己的代码,分享按钮在子组件里, at ...
- [Compose] 21. Apply Natural Transformations in everyday work
We see three varied examples of where natural transformations come in handy. const Right = x => ( ...
- JavaScript中的apply与call与arguments对象
(一) call方法 语法:presentObj.call(thisObj,arg1,arg2,arg3...) 参数thisObj :将被用作当前对象presentObj的对象. 当thisObj无 ...
- 闲聊js中的apply、call和arguments
JavaScript提供了apply和call两种调用方式来确定函数中的this的指向,在现实编码中,我确实 很少接触到这两个方法.但很无奈,很多面试题都要考这两种方法,我又没怎么用到,所以我们先来 ...
- kwargs - Key words arguments in python function
This is a tutorial of how to use *args and **kwargs For defining the default value of arguments that ...
- Default arguments and virtual function
Predict the output of following C++ program. 1 #include <iostream> 2 using namespace std; 3 4 ...
- [Ramda] Filter an Array Based on Multiple Predicates with Ramda's allPass Function
In this lesson, we'll filter a list of objects based on multiple conditions and we'll use Ramda's al ...
- JDK8新特性 -- Function接口: apply,andThen,compose
1 Function<T, R>中的T, R表示接口输入.输出的数据类型. R apply(T t) apply: .例子:func是定义好的Function接口类型的变量,他的输入.输出 ...
随机推荐
- 8.NPM 使用介绍
转自:http://www.runoob.com/nodejs/nodejs-tutorial.html NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使 ...
- Android 在滚动列表中实现视频的播放(ListView & RecyclerView)
这片文章基于开源项目: VideoPlayerManager. 所有的代码和示例都在那里.本文将跳过许多东西.因此如果你要真正理解它是如何工作的,最好下载源码,并结合源代码一起阅读本文.但是即便是没有 ...
- 不用浏览器,直接用代码发送文件给webservices所在服务器 并且可以周期行的发送
package com.toic.test; import java.io.DataInputStream; import java.io.DataOutputStream; import java. ...
- 开发板Ping不通虚拟机和主机
Ubuntu 16.04 win7 笔记本连接学校的无线网 开发板S3c2440与笔记本仅通过COM连接 问题描述: 设置了桥接,主机与虚拟机IP在同一网段后,主机与虚拟机可以Ping,但是 ...
- Django项目之Web端电商网站的实战开发(一)
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 目录 一丶项目介绍 二丶电商项目开发流程 三丶项目需求 四丶项目架构概览 五丶项目数据库设计 六丶项目框架搭建 一丶项目介绍 产品 ...
- 非常有用的sql脚本
/*sql 语法学习*/ /*函数的学习---------------------------------------*/ 获取当前时间(时/分/秒):select convert(varchar(1 ...
- 【软件project】机房收费系统之图形回想
[背景]通过一阶段的学习.自己整理了整理机房收费系统.以下想通过几张图来回顾一下机房的总体流程.此图形仅仅代表鄙人现阶段的理解.本文仅供參考,若有不妥的地方,请积极指正. 1.机房收费系统业务流程图 ...
- @转EXT2->EXT3->EXT4
Linux文件系统第一篇—从Ext2到Ext3再到Ext4 1 概述 Linux继承了UNIX一切皆文件的设计哲学,用文件和树形目录的抽象逻辑概念代替了硬盘和光盘等物理设备使用数据块的概念,用户使用文 ...
- Android中实现整个视图切换的左右滑动效果
Android中提供了一个Gallary,可以实现图片或者文本的左右滑动效果. 如何让整个视图都能实现左右滑动,达到类似于Gallary的效果呢?可以直接用一个开源的ViewFlow来实现. 项目 ...
- 洛谷 P1230 智力大冲浪
洛谷 P1230 智力大冲浪 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者m元.先不要太高兴!因为这些钱还不一定都是你的?! ...