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. SpringBoot+springmvc异步处理请求

    有两种情况,第一种是业务逻辑复杂,但不需要业务逻辑的结果,第二种是需要返回业务逻辑的处理结果 第一种比较简单,利用多线程处理业务逻辑,或者利用spring中@Asyn注解更简单, 使用@Asyn注解, ...

  2. CODEVS——T1519 过路费

    http://codevs.cn/problem/1519/ 时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master 题解  查看运行结果     题目描述 Desc ...

  3. 基于Eclipse的Android JNI层測试应用开发过程记录

    前言 本文记录一个Java层与JNI层參数与数据交互的应用程序开发过程.为实现一个功能完整的带Java与JNI的应用程序打下基础. 本文如果读者已搭建好Android的Eclipse与NDK开发环境, ...

  4. get_browser()用法

    get_browser()用法 get_browser()函数是用来分析USER_AGENT的,它的执行方法是自动获取客户端的USER_AGENT,然后调用browscap.ini库进行分析得到结果 ...

  5. Bitmap-把方形图片处理为圆形

    这个是直接在网上转载的,自己验证可靠 转载自http://my.oschina.net/zhouz/blog/213164 直接贴上代码 import android.graphics.Bitmap; ...

  6. Android时间对话框TimePickerDialog介绍

    目前网上流行着很多对“时间对话框TimePickerDialog”的讲解文章,但感觉都不是很详细.这里详细对该方面的知识进行介绍,旨在帮助初学者能够快速掌握该项技术. 首先要做的是声明一个日历类的对象 ...

  7. android 4.4 添加物理按键

    kernel下添加 Linux-3.4/drivers/input/keyboard/Makefile linux-3.4/drivers/input/keyboard/sw-keyboard.c s ...

  8. 洛谷—— P1967 货车运输 || COGS——C 1439. [NOIP2013]货车运输

    https://www.luogu.org/problem/show?pid=1967#sub  ||  http://www.cogs.pro/cogs/problem/problem.php?pi ...

  9. 电脑c盘清理

    https://www.cnblogs.com/btchenguang/archive/2012/01/20/2328320.html

  10. UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂)

    UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂) 题目链接 题目大意:假设有一个合数.然后它满足随意大于1小于n的整数a, 满足a^n%n = a;这种合数叫做Ca ...