Files
functional-programming-snake/fsharp/solutions/Util.fs
T

13 lines
446 B
FSharp

/// m01 util: small helpers used by every later module.
/// (The JavaScript track also writes `pipe` and `compose` here; F# has them built in as `|>` and `>>`.)
module Snake.Util
let range (n: int) : int list = [ 0 .. n - 1 ]
let dropLast (xs: 'a list) : 'a list =
match xs with
| [] -> []
| _ -> List.take (List.length xs - 1) xs
let contains (xs: 'a list) (p: 'a) (eq: 'a -> 'a -> bool) : bool = List.exists (fun x -> eq x p) xs