Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rec filter func list =
- match list with
- | x::xs when func xs -> x::(filter func xs)
- | _::xs -> filter func xs
- | [] -> []
- let rec count list =
- match list with
- | [] -> 0
- | x::xs -> 1 + count xs
- let first list =
- match list with
- | [] -> null
- | x::xs -> x
- let rec reverse list =
- match list with
- | [] -> []
- | x::xs -> reverse xs @ [x]
- let last list =
- match list with
- | [] -> null
- | x -> first (reverse x)
- let rec take list takeVal =
- match list, takeVal with
- | [], _ -> []
- | _, 0 -> []
- | x::xs, t -> x::(take xs (t - 1))
- let rec skip list skipVal =
- match list, skipVal with
- | x, s when s < 0 -> x
- | [], _ -> []
- | x, 0 -> x
- | x::xs, s -> skip xs (s - 1)
- let addToEnd list token =
- list @ [token]
- let addToBegin list token =
- token::list
- let removeAt list token =
- list |> filter (fun x -> x = token)
- let addToPosition list token position =
- (list |> take position) @ [token] @ (list |> skip position)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement