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. Python加密模块-pycryptodome

    这个模块可以避开Pycrypto安装时带来的一系列包依赖问题. 安装命令: pip install pycryptodome 使用实例: from Crypto.Cipher import AES k ...

  2. shell脚本基本用法

    下面是一些简单常用的脚本,工作中可能会用到,记录一下. #!/usr/bin/env bash #变量[=两边不要有空格], 在使用的时候需要用${变量名} 或者是$变量名 name="sa ...

  3. java中Dao模式

    什么是DAO   1.Data Access Object(数据存取对象) 2.位于业务逻辑和持久化数据之间 3.实现对持久化数据的访问 DAO模式的作用 1隔离业务逻辑代码和数据访问代码 2.隔离不 ...

  4. luogu P1011 车站

    题目描述 火车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上.下车,但上.下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人.从第3站起( ...

  5. 14. Cantor表

    时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 现代数学的著名证明之一是Georg Cantor证明了有理数 ...

  6. Codeforces Beta Round #10 D. LCIS 动态规划

    D. LCIS 题目连接: http://www.codeforces.com/contest/10/problem/D Description This problem differs from o ...

  7. python输出字符串,UnicodeEncodeError: 'ascii' codec can't encode characters in position问题

    2017-06-28更新:换到python3.x中,编码问题减少了很多.这篇博文不适用于python3.x http://blog.sina.com.cn/s/blog_64a3795a01018vy ...

  8. XuLA/XuLA2

    http://www.xess.com/prods/prod048.php XuLA http://www.xess.com/prods/prod055.php XuLA2 http://www.xe ...

  9. 东东糖博客MYSQL

    http://blog.chinaunix.net/uid-20785090-id-4328033.html

  10. 卸载oracle数据库

    Windows Registry Editor Version 5.00 [-HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\OracleOr ...