[Compose] Isomorphisms and round trip data transformations
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的更多相关文章
- 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 ...
- [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 ...
- Round trip 流程图
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢!
- 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 ...
- WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer)
原文:WCF技术剖析之十二:数据契约(Data Contract)和数据契约序列化器(DataContractSerializer) [爱心链接:拯救一个25岁身患急性白血病的女孩[内有苏州电视台经济 ...
- POJ1041 John's trip
John's trip Language:Default John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- 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- ...
- 【poj1041】 John's trip
http://poj.org/problem?id=1041 (题目链接) 题意 给出一张无向图,求字典序最小欧拉回路. Solution 这鬼畜的输入是什么心态啊mdzz,这里用vector储存边, ...
- poj 1041 John's trip 欧拉回路
题目链接 求给出的图是否存在欧拉回路并输出路径, 从1这个点开始, 输出时按边的升序输出. 将每个点的边排序一下就可以. #include <iostream> #include < ...
随机推荐
- JavaScript--数据结构之队列
5.1 队列的操作 队列是特殊的列表,只能一端入队(队尾)插入操作,一端出队(队头)删除操作.底层用数组,利用javascript数组优于其它语言的数组的方法,shift();删除第一个元素,push ...
- JS正则 replace()方法全局替换变量(可以对变量进行全文替换)
转至:https://www.cnblogs.com/jasonlam/p/7070604.html var text = "饿~,23333.饿~,测试yongde"; var ...
- ArcGIS Engine 线段绘制
转自ArcGIS Engine 线段绘制研究 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x ...
- KNIMI数据挖掘建模与分析系列_002_利用KNIMI做商超零售关联推荐
利用KNIMI做商超零售关联推荐 http://blog.csdn.net/shuaihj 一.測试数据 须要測试数据,请留下邮箱 二.训练关联推荐规则 1.读取销售记录(sales.table) 2 ...
- Activity Test1
源代码下载(免积分) :下载 Acitivty測试的API的父类是InstrumentationTestCase.这个类可以获取Instrumentation.来操作Activity. 对于acti ...
- VPS 的 CentOS6 升级 Python 的方法
VPS 的 CentOS6 升级 Python 的方法 centos默认安装python2.6.由于python和centos关联紧密,所以不建议卸载,进行编译升级 1.新开的VPS务必系统更新 yu ...
- Linux在应用层读写寄存器的方法
可以通过操作/dev/mem设备文件,以及mmap函数,将寄存器的地址映射到用户空间,直接在应用层对寄存器进行操作,示例如下: #include <stdio.h> #include &l ...
- 利用mysql5.6 的st_distance 实现按照距离远近排序。 (转载)
http://blog.csdn.net/zhouzhiwengang/article/details/53612481
- Ten ways to improve the performance of large tables in MySQL--转载
原文地址:http://www.tocker.ca/2013/10/24/improving-the-performance-of-large-tables-in-mysql.html Today I ...
- 应用Python来计算排列中的逆序数个数
在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.一个排列中所有逆序总数叫做这个排列的逆序数.也就是说,对于 ...