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 .


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

查看所有标签

猜你喜欢:

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

AJAX HACKS中文版

AJAX HACKS中文版

帕里 / 2007-3 / 55.00元

《AJAX HACKS中文版:创建快速响应Web站点的工具和技巧》完全挖掘出了Ajax技术的优点,以手把手的方式教您如何揭开Ajax的神秘面纱。每个hack代表了完成某个特定任务的精巧方法,从而为您节省了大量的时间。 《AJAX HACKS中文版:创建快速响应Web站点的工具和技巧》搜集了80个有关Ajax技术的技巧,覆盖了该技术的所有亮点。你现在就想构建下一代Web应用吗?《AJAX HA......一起来看看 《AJAX HACKS中文版》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

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

Markdown 在线编辑器