-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5260b4b
commit 31886f2
Showing
3 changed files
with
39 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Lib.Range (Range(..), mkRange, getOverlap, map, start, end) where | ||
|
||
import Prelude hiding (map) | ||
|
||
newtype Range = Range (Integer, Integer) | ||
|
||
mkRange :: (Integer, Integer) -> Maybe Range | ||
mkRange r@(x1, x2) | ||
| x1 <= x2 = Just $ Range r | ||
| otherwise = Nothing | ||
|
||
getOverlap :: Range -> Range -> Maybe Range | ||
getOverlap (Range (x1, x2)) (Range (y1, y2)) | ||
| x2 < y1 || y2 < x1 = Nothing | ||
| otherwise = Just $ Range (max x1 y1, min x2 y2) | ||
|
||
map :: (Integer -> Integer) -> Range -> Range | ||
map f (Range (x1, x2)) = Range (f x1, f x2) | ||
|
||
start :: Range -> Integer | ||
start (Range (s, _)) = s | ||
|
||
end :: Range -> Integer | ||
end (Range (_, e)) = e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters