Skip to content

Instantly share code, notes, and snippets.

@monkieboy
Created Nov 17, 2015
Embed
What would you like to do?
Playing with ranges
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