Relate intervals with Rampart

栏目: IT技术 · 发布时间: 4年前

内容简介:Have you ever needed to know if two intervals overlap? I wroteThe other day at work we were working on a system that needed to select accounts that were active during a certain timeframe. This seemingly simple problem prompted a bunch of discussion. We spe

Have you ever needed to know if two intervals overlap? I wrote Rampart , a small Haskell library to help with that.

The other day at work we were working on a system that needed to select accounts that were active during a certain timeframe. This seemingly simple problem prompted a bunch of discussion. We spent some time puzzling through inequalities before we landed on something that everyone agreed would do what we wanted. I figured we could save ourselves and others time in the future by making a library to handle the tricky interval logic.

You may be thinking that this is a trivial problem. Did you know that there are 13 different ways that two intervals can relate to each other? Here they are:

Relate intervals with Rampart

Rampart is a tiny Haskell module that can take two intervals and tell you how they relate. For example, how does the interval from 2 to 4 relate to the interval from 3 to 5?

>>> import Rampart
>>> relate (toInterval (2, 4)) (toInterval (3, 5))
Overlaps

It’s easy to show off with numbers, but it works with anything that’s orderable: dates, times, money, and so on. So if you find yourself asking questions about intervals, consider using Rampart to answer them.

You can find the documentation here: https://hackage.haskell.org/package/rampart-1.0.0.1/docs/Rampart.html .


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

CSS权威指南(第三版·英文影印版)

CSS权威指南(第三版·英文影印版)

[美] Eric A.Meyer / 东南大学出版社 / 2007-06 / 68.00元

著名的CSS专家Eric A.Meyer他招牌式的智慧和无与伦比的经验引领读者探索了CSS的各个部 分,包括属性、标记、特性和实现。此外,他还就现实应用中的一些问题,例如浏览器的支持和设计方针,发表了看法。你所要知道的就是HTML 4.0的知识,这样就可以创建整洁、易于维护的脚本,以与桌面出版系统同样的优雅和控制能力管理网站布局和分页。你将会学到: 精妙地设计文本风格 用户界面、......一起来看看 《CSS权威指南(第三版·英文影印版)》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具