Skip to content

Instantly share code, notes, and snippets.

@theimowski
Created May 16, 2015 21:22
Show Gist options
  • Save theimowski/3420badfa65f778a993a to your computer and use it in GitHub Desktop.
Save theimowski/3420badfa65f778a993a to your computer and use it in GitHub Desktop.
let (|Contains|_|) xs input =
let rec contains xs' input' acc =
match xs', input' with
| [], after ->
let length = List.length acc - List.length xs
let before = acc |> List.rev |> Seq.take length |> List.ofSeq
Some (before, after)
| _, [] -> None
| h1 :: t1, h2 :: t2 when h1 = h2 ->
contains t1 t2 (h2 :: acc)
| h1 :: t1, h2 :: t2 ->
contains xs t2 (h2 :: acc)
contains xs input []
match [0;0;7;6;7;1;3;7;6;7;0;0] with
| Contains [7;6;7] (before,after) -> printfn "before: %A; after: %A" before after
| _ -> printfn "does not contain"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment