Last active
August 29, 2015 14:10
-
-
Save chrismckelt/d9d113edc3d3bf4afe91 to your computer and use it in GitHub Desktop.
F# AsyncSeq anagram checker -- async run through a list pulling out found results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CodeDojo | |
module CodeDojo_Anagram = | |
open System | |
open System.ServiceModel | |
open System.Collections.Generic | |
open Microsoft.FSharp.Linq | |
open FSharp.Control | |
[<Literal>] | |
let testWord = "table" | |
let testWords = new List<string>() | |
testWords.Add("bleat") | |
testWords.Add("blate") | |
testWords.Add("junk") | |
let hasWord (word:string) = | |
let mutable res = true | |
let a = testWord.ToCharArray() |> Set.ofArray | |
let b = word.ToCharArray() |> Set.ofArray | |
let difference = Set.intersect a b | |
match difference.Count with | |
| 0 -> false | |
| _ -> true | |
let test2 (words:List<string>, (word:string)) : AsyncSeq<string> = | |
asyncSeq { | |
let res = | |
(words) | |
|> Seq.filter(fun x-> (hasWord(x)) ) | |
|> AsyncSeq.ofSeq | |
yield! res | |
} | |
let runTest = test2(testWords,testWord) | |
|> AsyncSeq.toObservable | |
|> fun a -> a.Subscribe(fun x -> printfn "Found '%A' " x) | |
|> ignore | |
() | |
Can I run in Linqpad?
yes mate - f sharp program
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
let results = CodeDojo.CodeDojo_Anagram.runTest
Console.WriteLine("Press any key to continue...");