Relate intervals with Rampart

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

内容简介: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 .


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

查看所有标签

猜你喜欢:

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

计算机算法基础

计算机算法基础

沈孝钧 / 机械工业出版社 / 2013-11 / 45.00元

计算机算法是计算机科学的一个重要分支,也是一个难点。本书作者根据自己20多年在国内、国外的教学与科研实践,系统地总结了计算机算法的设计与分析方法,覆盖了大部分最主要的算法技术,包括:分治法、贪心法、动态规划、图的遍历技术、穷举搜索等,涉及一系列重要的算法问题,包括排序问题、选择问题、最小生成树问题、最短路径问题、网络流问题、二分图的匹配问题、字符串的匹配问题和几何算法问题等,还介绍了问题本身的计算......一起来看看 《计算机算法基础》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器