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. python3 怎么爬取新闻网站?

    先开个坑,以后再填吧....... import requests from bs4 import BeautifulSoup def content(url): text = requests.ge ...

  2. Educational Codeforces Round 38 部分题解

    D. Buy a Ticket 分析 建一个源点,连向所有结点,边的花费为那个结点的花费,图中原有的边花费翻倍,最后跑一遍最短路即可. code #include<bits/stdc++.h&g ...

  3. php 5.6 安装openssl extension 出现编译错误

    废话不多说,直接上问题: PHP和openssl extension都是最新版本的,标准步骤安装时候出现如下问题: php:php-5.6.27 openssl:openssl-1.1.0e ==== ...

  4. 搭建samba 共享openstack开发环境

    centos7.2 openstack环境为allinone 模式,这样跑代码好处理 安装smb [root@controller ~]# yum install -y samba samba-cli ...

  5. mac系统终端下忽略大小写 与 git自动补全(git auto completion)

    1.下载git-completion.bash 并放到home 目录下: curl https://raw.githubusercontent.com/git/git/master/contrib/c ...

  6. socket的使用一

    socket概念 socket层 理解socket Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协 ...

  7. linux常见命令集合(下)

    1. tar zcvf backup-$(date "+%Y-%m-%d").tar.gz demo01dir 常用命令集合 echo helloworld date “+%y-% ...

  8. [转]java中Collections.sort排序详解

      Comparator是个接口,可重写compare()及equals()这两个方法,用于比价功能:如果是null的话,就是使用元素的默认顺序,如a,b,c,d,e,f,g,就是a,b,c,d,e, ...

  9. Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数

    D. Soldier and Number Game Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  10. Codeforces Round #300 C. Tourist's Notes 水题

    C. Tourist's Notes Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pr ...