In previous post, Arrow Functor with contramap, we have seen how to opreating on params before we invoke the function by using Arrow + contramap. It happens before function get inovked, before we get result. We can say this opreation happens on the left hand side of function (which is the params).

In this post, we will see how to opreate on the right handside of function, which is our result.

const Arrow = require('crocks/Arrow');
const chain = require('crocks/pointfree/chain');
const option = require('crocks/pointfree/option');
const prop = require('crocks/Maybe/prop');
const safe = require('crocks/Maybe/safe'); const getName = compose(
option('no name'),
chain(safe(isString)),
prop('name')
)
const arrUpper = Arrow(
str => str.toUpperCase()
)
const welcome = str => `Welcome. ${str}!`;
const nameUpper = arrUpper
.contramap(getName)
.map(welcome) log(
nameUpper.runWith({name: 'zhentian'})
) // 'Welcome. ZHENTIAN!'

So after 'contramap', we chian 'map(welcome)'. this will wrap the result from 'arrUpper' into a new String.

Notice that it is equivalent that:

const nameUpper = arrUpper
.map(welcome)
.contramap(getName) const nameUpper = arrUpper
.contramap(getName)
.map(welcome)

We can also shorter the syntax by using 'promap', it is the same as 'contramap + map':

const nameUpper = arrUpper
.promap(getName, welcome)

[Functional Programming] Arrow contramap vs map and promap的更多相关文章

  1. [Functional Programming] Arrow Functor with contramap

    What is Arrow Functor? Arrow is a Profunctor that lifts a function of type a -> b and allows for ...

  2. Beginning Scala study note(4) Functional Programming in Scala

    1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...

  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. Functional Programming without Lambda - Part 2 Lifting, Functor, Monad

    Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...

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

  6. BETTER SUPPORT FOR FUNCTIONAL PROGRAMMING IN ANGULAR 2

    In this blog post I will talk about the changes coming in Angular 2 that will improve its support fo ...

  7. [Functional Programming] Function signature

    It is really important to understand function signature in functional programming. The the code exam ...

  8. Sth about 函数式编程(Functional Programming)

    今天开会提到了函数式编程,针对不同类型的百年城方式,查阅了一部分资料,展示如下: 编程语言一直到近代,从汇编到C到Java,都是站在计算机的角度,考虑CPU的运行模式和运行效率,以求通过设计一个高效的 ...

  9. Coursera公开课Functional Programming Principles in Scala习题解答:Week 2

    引言 OK.时间非常快又过去了一周.第一周有五一假期所以感觉时间绰绰有余,这周中间没有假期仅仅能靠晚上加周末的时间来消化,事实上还是有点紧张呢! 后来发现每堂课的视频还有相应的课件(Slide).字幕 ...

随机推荐

  1. Android app开发中用户协议(使用条款)文字自己主动换行

    用户协议(使用条款)文字自己主动换行处理 转载请注明出处:http://blog.csdn.net/u012301841/article/details/46648821 我们在开发app的时候.常常 ...

  2. Android 开源库获取途径整理

    介绍眼下收藏 Android 开源库比較多的 GitHub 项目.站点.Twitter.App 及怎样获取最新的 Android 开源库. 微信号: 1. GitHub Android 开源项目汇总 ...

  3. SWD Connect/Transfer Source Code

    Serial Wire Debug interface The Serial Wire Debug protocol operates with a synchronous serial interf ...

  4. 【Go命令教程】7. go run

    Go 源码文件包括:命令源码文件.库源码文件 和 测试源码文件.其中,命令源码文件 总应该属于 main 代码包,且在其中有无参数声明.无结果声明的 main 函数.单个命令源码文件可以被单独编译,也 ...

  5. lex yacc flex bison

    lex与yacc是两个在Unix下的分别作词法分析和语法分析的工具, Linux对应flex与bison. windows:http://sourceforge.net/projects/unxuti ...

  6. Win10年度更新开发必备:VS2015 正式版下载汇总

    ============================================================================ 微软在07月20日发布了Visual Stud ...

  7. Java知识回顾 (1) 编译环境与基本变量类型

    参考资料 runoob Java知识回顾序列的相关资料,主要来自 runoob,并对其中的知识进行概况或总结,去除对一个之前了解过Java的人员无关的知识点.以便能够使得一个新手,或之前有Java经验 ...

  8. 【mysql】update的in的嵌套查询更新,如果字段中包含字符串A,统一替换为字符串B

    对于select的in嵌套子查询[DQL]: select en_name from goods where uid in( select uid from goods where goods_typ ...

  9. android Installation error: INSTALL_FAILED_VERSION_DOWNGRADE

    http://www.apkbus.com/android-114019-1-1.html   提高 AndroidManifest.xml中的manifest的android:versionCode ...

  10. Web安全测试漏洞场景

    HTTP.sys 远程代码执行   测试类型: 基础结构测试   威胁分类: 操作系统命令   原因: 未安装第三方产品的最新补丁或最新修订程序   安全性风险: 可能会在 Web 服务器上运行远程命 ...