pointed functor is a functor with an of method

class IO {
// The value we take for IO is always a function!
static of (x) {
return new IO(() => x)
} constructor (fn) {
this.$value = fn;
} map (fn) {
return new IO(compose(fn, this.$value))
}
}

What's important here is the ability to drop any value in our type and start mapping away.

IO.of('tetris').map(concat(' master'));
// IO('tetris master') Maybe.of().map(add());
// Maybe(1337) Task.of([{ id: }, { id: }]).map(map(prop('id')));
// Task([2,3]) Either.of('The past, present and future walk into a bar...').map(concat('it was tense.'));
// Right('The past, present and future walk into a bar...it was tense.')

The benifits using 'of' instead of 'new' is that we can map over the 'Task.of().map(fn)' right away.

Consider this:

const m = new Maybe():
m.map(add()) //VS Maybe.of().map(add());

To avoid the new keyword, there are several standard JavaScript tricks or libraries so let's use them and use of like a responsible adult from here on out. I recommend using functor instances from folktaleramda or fantasy-land as they provide the correct of method as well as nice constructors that don't rely on new.

[Functional Programming] Pointy Functor Factory的更多相关文章

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

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

  3. 关于函数式编程(Functional Programming)

    初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...

  4. [Functional Programming] Function signature

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

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

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

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

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

  8. Functional programming

    In computer science, functional programming is a programming paradigm, a style of building the struc ...

  9. Java 中的函数式编程(Functional Programming):Lambda 初识

    Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...

随机推荐

  1. 洛谷P3435 [POI2006]OKR-Period of Words [KMP]

    洛谷传送门,BZOJ传送门 OKR-Period of Words Description 一个串是有限个小写字符的序列,特别的,一个空序列也可以是一个串. 一个串P是串A的前缀, 当且仅当存在串B, ...

  2. Python并发编程-多进程socketserver简易版

    普通版的socketserver #server.py import socket sk = socket.socket() sk.bind(('127.0.0.1',8080))#建立连接 sk.l ...

  3. Web应用程序信息收集工具wig

    Web应用程序信息收集工具wig   很多网站都使用成熟的Web应用程序构建,如CMS.分析网站所使用的Web应用程序,可以快速发现网站可能存在的漏洞.Kali Linux新增加了一款Web应用程序信 ...

  4. Mac 配置几个环境变量

    终端    open -t ~/.bash_profile  打开.bash_profile export PATH=${PATH}:/Users/maxinliang/Android/sdk/pla ...

  5. Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力

    A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given ...

  6. IDA 中文字符串

    http://www.pediy.com/kssd/pediy05/pediy50528.htm Ida Pro 的默认设置里对中文字串的支持比较差,对于首字节大于'E0'的都显示成?了.其实...  ...

  7. Time Step Too Small in Multisim

    http://digital.ni.com/public.nsf/allkb/4B99B2CD6C0C3B6A86257205005D58E0 Error: Time Step Too Small i ...

  8. maven,阿里云国内镜像,提高jar包下载速度

    镜像 maven默认会从中央仓库下载jar包,这个仓库在国外,而且全世界的人都会从这里下载,所以下载速度肯定是非常慢的.镜像就相当于是中央仓库的一个副本,内容和中央仓库完全一样,目前有不少国内镜像,其 ...

  9. Unity 网络请求(1)

    using UnityEngine; using System.Collections; public class Scene1 : MonoBehaviour { //下载图片的容器 private ...

  10. linux之inode

    一.inode是什么? 理解inode,要从文件储存说起. 文件储存在硬盘上,硬盘的最小存储单位叫做”扇区”(Sector).每个扇区储存512字节(相当于0.5KB). 操作系统读取硬盘的时候,不会 ...