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. POJ 1743 Musical Theme (字符串HASH+二分)

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15900   Accepted: 5494 De ...

  2. Task.FromResult应用场景举例

    Task.FromResult用来创建一个带返回值的.已完成的Task. 场景一:以同步的方式实现一个异步接口方法 比如有一个接口包含异步方法. interface IMyInterface { Ta ...

  3. 在ASP.NET MVC下扩展一个带验证的RadioButtonList

    在ASP.NET MVC4中,HtmlHelper为我们提供了Html.RadioButton()方法用来显示Radio Button单选按钮.如果想显示一组单选按钮,通常的做法是遍历一个集合把每个单 ...

  4. DirectX - dds图片格式(DDSURFACEDESC2)

    DDS是DirectDraw Surface的缩写,它是DirectX纹理压缩(DirectX Texture Compression,简称DXTC)的产物. DXTC减少了纹理内存消耗的50%甚至更 ...

  5. C#编程(三十六)----------元组

    元组 数组合并了相同类型的对象,而元组合并了不同类型的对象. .NET 4定义了8个泛型Tuple类和一个静态的Tuple类,他们用作元组的工厂. 元组是一种数据结构,通过逗号分隔 Tuple< ...

  6. WordPress主题开发:优化标题

    页面使用: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  7. Oracle 专用模式(DEDICATED) 和 共享模式(SHARE)

    Oracle 是一门博大精深的技术.玩了2年的oracle,依旧还有很多知识点不清楚. 昨天群里的朋友提到了 DEDICATED 和 SHARE 两种模式. 不清楚,默默的做点功课了.从网上搜了点知识 ...

  8. websocket消息推送实现

    一.服务层 package com.demo.websocket; import java.io.IOException; import java.util.Iterator; import java ...

  9. win7凭据管理、win7多用户远程登录、主机头设置、nuget.org无法访问

    前言  最近遇到的几个问题,然后处理在此对处理方式进行记录一下. 1.服务器共享文件夹,在本机进行访问登录时,每次登录或者每次开机进入都要进行登录的权限认证,这样很麻烦. 2.服务器难免会有多用户同时 ...

  10. nginx 413 500报错

    采用nginx作反向代理,出现了一个诡异的问题,小文件可以提交,大文件会报500内部错误.这个是什么原因导致的呢? 查wiki可知,上传文件大小相关的有三个配置 client_body_buffer_ ...