What is Isomorphisms?
We have a value x, then apply function 'to' and 'from' to value 'x', the result we should still get 'x'.

// from(to(x)) == x
// to(from(y)) == y

So Isomorphisms is kind of opreation able to tranform a value back and forward without lose anything.

Example1:

const Iso = (to, from) => ({
to,
from
}) // String <-> [Chat]
const StoC = Iso(
(str) => str.split(''),
(chat) => chat.join('')
); const res = StoC.from(StoC.to('How'));

Example2:

// String <-> [Chat]
const StoC = Iso(
(str) => str.split(''),
(chat) => chat.join('')
); const truncate = (str, num) => StoC.from(StoC.to(str).slice(,num)).concat('...');
let res = truncate("Hello World!", );
console.log(res); // "Hello W..."

Example3:

const Iso = (to, from) => ({
to,
from
}) // [a] <-> Either/null/a
const singleton = Iso(
(either) => either.fold(() => [], x => [x]),
([x]) => x? Right(x): Left()
) const filterEither = (e, pred) => singleton.from(singleton.to(e).filter(pred));
const res = filterEither(Right('hello'), (x) => x.match(/h/ig))
.map(x => x.toUpperCase());

[Compose] Isomorphisms and round trip data transformations的更多相关文章

  1. Data obtained from ping: is it round trip or one way?

    I have 2 servers, each in two separate locations. I need to host an application on one, and the data ...

  2. [Ramda] Declaratively Map Data Transformations to Object Properties Using Ramda evolve

    We don't always control the data we need in our applications, and that means we often find ourselves ...

  3. Round trip 流程图

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢!

  4. Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 读取关系数据

    Reading related data¶ 9 of 9 people found this helpful The Contoso University sample web application ...

  5. WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)

    原文:WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer) [爱心链接:拯救一个25岁身患急性白血病的女孩[内有苏州电视台经济 ...

  6. POJ1041 John's trip

    John's trip Language:Default John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...

  7. How Google Backs Up The Internet Along With Exabytes Of Other Data

    出处:http://highscalability.com/blog/2014/2/3/how-google-backs-up-the-internet-along-with-exabytes-of- ...

  8. 【poj1041】 John's trip

    http://poj.org/problem?id=1041 (题目链接) 题意 给出一张无向图,求字典序最小欧拉回路. Solution 这鬼畜的输入是什么心态啊mdzz,这里用vector储存边, ...

  9. poj 1041 John's trip 欧拉回路

    题目链接 求给出的图是否存在欧拉回路并输出路径, 从1这个点开始, 输出时按边的升序输出. 将每个点的边排序一下就可以. #include <iostream> #include < ...

随机推荐

  1. Spider_req

    requests模块 安装(用管理员身份去打开Anaconda Prompt) conda install requests python -m pip install requests # 以管理员 ...

  2. session应用二

    从session中获取mapper对象,利用mapper对象进行增删改查 Date now = new Date(); SqlSession session = this.yangchebaoDbMa ...

  3. HttpClient的基本使用

    HttpClient的基本使用 前言 HttpClient是Apache提供的一个用于在Java中处理HTTP请求.响应操作的工具,由于JDK自带的API对HTTP协议的支持不是很友好,使用起来也不是 ...

  4. 编译安装PHP-7.2.8

    一 下载并软件包 wget http://124.205.69.169/files/A218000006E9730A/cn2.php.net/distributions/php-7.2.8.tar.g ...

  5. 【CS Round #43 D】Bad Triplet

    [链接]点击打开链接 [题意] 给你n个点m条边的无权无向联通图; 让你找3个点A,B,C 使得A->B=B->C=A->C 这里X->Y表示点X到点Y的最短路长度. [题解] ...

  6. 比較C++和Java 二

    26.Java内置多线程支持.你能够通过继承Thread类来创建一个新的线程(重写run()方法).相互排斥发生在使用synchronized关键字作为类型修饰符修饰方法的对象级别. 在任一时刻,仅仅 ...

  7. R语言-回归

    定义: 回归是统计学的核心,它其实是一个广义的概念,通常指那些用一个或多个预测变量来预测响应变量.既:从一堆数据中获取最优模型参数 1.线性回归 1.1简单线性回归 案例:女性预测身高和体重的关系 结 ...

  8. zookeeper分布式协调服务的使用一

    Zookeeper是一个高性能,分布式的应用协调服务. 提供服务: 1.集群成员的管理(Group Membership) 2.分布式锁(Locking) 3.选主(Leader Election) ...

  9. swift开发网络篇—NSURLConnection基本使用

    iOS开发网络篇—NSURLConnection基本使用 一.NSURLConnection的常用类 (1)NSURL:请求地址 (2)NSURLRequest:封装一个请求,保存发给服务器的全部数据 ...

  10. MongoDb 查询时常用方法

    Query.All("name", "a", "b");//通过多个元素来匹配数组Query.And(Query.EQ("name ...