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.

  1. const $ = selector =>
  2. Either.of({selector, height: })
  3.  
  4. const getScreenSize = (screen, header, footer) => screen - (header + footer);
  5.  
  6. $('header').chain(header =>
  7. $('footer').map(footer =>
  8. getScreenSize(, header, footer)
  9. )
  10. )

This happens in sequential, we can use currey function to improve the code:

  1. const getScreenSize = screen => header => footer => screen - (header + footer);
  1. Either.of(getScreenSize)
  2. .ap($('header'))
  3. .ap($('footer'))

Or we can use:

  1. const liftA2 = (f, fx, fy) =>
  2. fx.map(f).ap(fy)
  1. const res = liftA2(getScreenSize(800), $('header'), $('footer'))

[Compose] 16. Apply multiple functors as arguments to a function (Applicatives)的更多相关文章

  1. 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 ...

  2. 小程序分享报错 Cannot read property 'apply' of null;at page XXX onShareAppMessage function

    Cannot read property 'apply' of null;at page XXX onShareAppMessage function 然后看了下自己的代码,分享按钮在子组件里, at ...

  3. [Compose] 21. Apply Natural Transformations in everyday work

    We see three varied examples of where natural transformations come in handy. const Right = x => ( ...

  4. JavaScript中的apply与call与arguments对象

    (一) call方法 语法:presentObj.call(thisObj,arg1,arg2,arg3...) 参数thisObj :将被用作当前对象presentObj的对象. 当thisObj无 ...

  5. 闲聊js中的apply、call和arguments

    JavaScript提供了apply和call两种调用方式来确定函数中的this的指向,在现实编码中,我确实 很少接触到这两个方法.但很无奈,很多面试题都要考这两种方法,我又没怎么用到,所以我们先来 ...

  6. 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 ...

  7. Default arguments and virtual function

    Predict the output of following C++ program. 1 #include <iostream> 2 using namespace std; 3 4 ...

  8. [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 ...

  9. JDK8新特性 -- Function接口: apply,andThen,compose

    1 Function<T, R>中的T, R表示接口输入.输出的数据类型. R apply(T t) apply: .例子:func是定义好的Function接口类型的变量,他的输入.输出 ...

随机推荐

  1. 1.20 Python基础知识 - python常用模块-1

    一.time和datetime 1.time模块 1)time.process_time() >>> import time >>> time.process_ti ...

  2. Akka边学边写(4)-- MiniRPG

    前面几篇文章用Akka写了HelloWorld和EchoServer,为了更进一步学习Akka,本文将会实现一个非常小的RPG游戏server:MiniRPG. 游戏逻辑 由于是迷你RPG,所以逻辑非 ...

  3. [React & Testing] Snapshot testings

    For example we have a React comonent: -- A toggle button, we want to test. When it si toggle on, the ...

  4. 《Java实战开发经典》第五章5.3

    package xiti5; public class Third { public static void main(String[] args) { T t=new T("want yo ...

  5. IOS系统不兼容position: fixed;属性的解决方案

    position: fixed;属性在IOS系统手机上会有很明显的抖动,解决方式: 只需要在中间部分外层div添加css样式position:fixed;top:50px; bottom:50px;o ...

  6. Vue使用Promise自定义confirm确认框组件

    使用Promise模拟浏览器确认框,可自定义标题,内容,按钮文字和类型 参数名 类型 说明 title String 标题 content String 内容 yesBtnText String 确认 ...

  7. Eclipse如何从导入SVN上导入项目

    1.右键单击,选择 Import,进入导入项目窗口 2.点击选择从SVN检出项目,点击Next下一步 3.选择创建新的资源库位置,点击Next,如果项目之前已经导入过删除掉了,重新导入的时候,只需勾选 ...

  8. 为什么要学习Numerical Analysis

    前几日我发了一个帖子,预告自己要研究一下  Numerical Analysis 非常多人问我为啥,我统一回答为AI-----人工智能 我在和教授聊天的时候,忽然到了语言发展上 我说:老S啊(和我关系 ...

  9. vue使用(二)

    本节目标:           1.数据路径的三种方式          2.{{}}和v-html的区别 1.绑定图片的路径 方法一:直接写路径 <img src="http://p ...

  10. linux中软件安装方式

    通常Linux应用软件的安装包有三种: tar包,如software-1.2.3-1.tar.gz.它是使用UNIX系统的打包工具tar打包的. rpm包,如software-1.2.3-1.i386 ...