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. Dubbo学习总结(4)——Dubbo基于Zookeeper实现分布式实例

    入门实例解析 第一:provider-提供服务和相应的接口 创建DemoService接口 [java] view plaincopyprint? <span style="font- ...

  2. 读《互联网创业password》之随想

    活动地址:http://blog.csdn.net/blogdevteam/article/details/38657235. 现如今.互联网已经深深的影响了中国人的日常生活习惯,曾经那种通过网络进行 ...

  3. xcode6.3 模版位置

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templ ...

  4. J2SE核心开发实战(一)——认识J2SE

    认识J2SE 一.课程简单介绍 在本章学习開始前,你应该具备一些Java的基础知识. 我们将在本章来认识J2SE,并复习一下前面学过的面向对象的相关知识. 注:全部的蓝色文字都是带超链接的,这些链接是 ...

  5. jedate-开始使用一款好用的时间插件

    jeDate日期控件 -(原生JS版)jeDate V6.5.0 是一款原生JS开发的 不依赖任何第三方库 大众化的日期控件,包含 多语言.设定年月(YYYY-MM).日期范围限制.开始日期设定.自定 ...

  6. jvm compile

    >>>Making sec-files-win @ Thu Oct 17 20:34:02 CST 2013 ... >>>Making jgss-files @ ...

  7. Android 一个异步SocketHelper

    发送流程:首先定义一个缓冲池,发送数据时仅仅是将待发送的数据加入到缓冲池中,再由后台的工作线程从缓冲池中取得待发送数据进行发送.可能某些情况下在数据发送完成时需要做一些处理(比如写日志),便定义了一个 ...

  8. softmax 与 sigmoid & softmax名字的由来

    Softmax回归模型,该模型是logistic回归模型在多分类问题上的推广. 参考:http://blog.csdn.net/u014422406/article/details/52805924 ...

  9. amazeui页面分析2

    amazeui页面分析2 一.总结 1.弄清结构:这些部分都是一块一块分好了的,掌握结构之后,想替换哪块就替换哪块,想不要哪块就不要哪块,非常简单的 2.一块一块:替换十分简单 3.弄清楚大块之后,然 ...

  10. lettuce--Advanced Redis client

    redis官方提供的java client: git地址:https://github.com/mp911de/lettuceAdvanced Redis client for thread-safe ...