Skip to content

Instantly share code, notes, and snippets.

@monkieboy
Created November 17, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkieboy/62a5a0e5e4ca62f06ffe to your computer and use it in GitHub Desktop.
Save monkieboy/62a5a0e5e4ca62f06ffe to your computer and use it in GitHub Desktop.
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