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. canvas:动态时钟

    此时针是以画布的中心为圆心: ctx.translate(width/2,width/2); 此函数是将画布的原点移到(width/2,width/2) 数字的位置我们利用了三角函数的原理 x=rco ...

  2. Appium_python3使用汇总

    1. 对webview页面元素的处理self.driver.switch_to.context("WEBVIEW_com.aaa.bbb")source = self.driver ...

  3. CISP/CISA 每日一题 17

     CISSP 每日一题(答) What are often added to passwords to maketheir resultant hash secure and resistant to ...

  4. 洛谷 P1795 无穷的序列_NOI导刊2010提高(05)

    P1795 无穷的序列_NOI导刊2010提高(05) 题目描述 有一个无穷序列如下: 110100100010000100000… 请你找出这个无穷序列中指定位置上的数字 输入输出格式 输入格式: ...

  5. C++ 指针与引用 知识点 小结

    [摘要] 指针能够指向变量.数组.字符串.函数.甚至结构体.即指针能够指向不同数据对象.指针问题 包含 常量指针.数组指针.函数指针.this指针.指针传值.指向指针的指针 等. 主要知识点包含:1. ...

  6. 深入理解HTTP协议及原理分析之缓存(3种缓存机制)

    3.2 缓存的实现原理 3.2.1什么是Web缓存 WEB缓存(cache)位于Web服务器和客户端之间. 缓存会根据请求保存输出内容的副本,例如html页面,图片,文件,当下一个请求来到的时候:如果 ...

  7. amazeui学习笔记一(开始使用2)--布局示例layouts

    amazeui学习笔记一(开始使用2)--布局示例layouts 一.总结 1.样例分析(不要忘记,优先分析这个布局示例):有教你页面怎么布局的,实例中可以分析一波 2.响应式:对应meta标签中的v ...

  8. 解决Win8/8.1无法正确识别USB3.0的问题

    找一个USB3.0的移动硬盘到了手里竟然变成2.0的了!二了! 不能忍啊. 听说是快速启动的问题,但是开机速度快很诱人. 百度了其他解决方法,终于解决了. 下面摘录自: http://blog.csd ...

  9. Altium Designer如何改两个原件之间的安全距离

    在pcb中按 D R 一个事垂直距离, 另一个是水平距离.

  10. Javascript和jquery事件--阻止事件冒泡和阻止默认事件

    阻止冒泡和阻止默认事件—js和jq相同,jq的event是一个全局的变量 我们写代码的时候常用的都是事件冒泡,但是有的时候我们并不需要触发父元素的事件,而浏览器也有自己的默认行为(表单提交.超链接跳转 ...