Skip to content

Instantly share code, notes, and snippets.

@hudo
Created August 11, 2015 19:47
Show Gist options
  • Select an option

  • Save hudo/6425c5ebe7b6fabfe66b to your computer and use it in GitHub Desktop.

Select an option

Save hudo/6425c5ebe7b6fabfe66b to your computer and use it in GitHub Desktop.
let matches (pattern : string) (x : string) : bool =
let rec matchesL pattern x =
match pattern, x with
| [], [] -> true
| '?'::pTail, xHead::xTail -> matchesL pTail xTail || matchesL pTail x
| '*'::pTail, xHead::xTail -> matchesL pTail xTail || matchesL pTail x || matchesL pattern xTail
| pHead::pTail, xHead::xTail when pHead = xHead -> matchesL pTail xTail
| _ -> false
matchesL (Seq.toList pattern) (Seq.toList x)
let findMatches (pattern : string) (xs : seq<string>) : seq<string> =
Seq.where (matches pattern) xs
[<EntryPoint>]
let main argv =
["crisis"; "cristian"; "cris"; "acris"; "crielikeababis"; "criesd"]
|> findMatches "*a?"
|> String.concat ","
|> printfn "Result is %s"
System.Console.ReadLine() |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment