Created
November 17, 2015 14:07
-
-
Save monkieboy/62a5a0e5e4ca62f06ffe to your computer and use it in GitHub Desktop.
Playing with ranges
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
let (..) (start:int) (limit:int) = | |
let sequence = [start..limit] | |
let decapitate h t = | |
if t = List.empty | |
then [ h ] | |
else t |> List.rev | |
let reversed = | |
match sequence with | |
| h::t -> decapitate h t | |
| [] -> List.empty | |
if (reversed |> List.length > 1) | |
then | |
match reversed with | |
| h::t -> List.toSeq (decapitate h t) | |
| [] -> Seq.empty | |
else Seq.empty | |
let logAndAssert actual expected = | |
printfn "expect %A to be %A: result %A: (expected=%A:actual=%A)" actual expected (expected=actual) expected actual | |
let t1 = [0..-1] | |
let t2 = [0..0] | |
let t3 = [0..1] | |
let t4 = [0..2] | |
let t5 = [5..9] | |
let t6 = [-3..2] | |
logAndAssert t1 [] | |
logAndAssert t2 [] | |
logAndAssert t3 [] | |
logAndAssert t4 [1] | |
logAndAssert t5 [6;7;8] | |
logAndAssert t6 [-2;-1;0;1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment