Skip to content

Instantly share code, notes, and snippets.

@kos59125
Forked from anonymous/FindDuplicate.fs
Last active December 14, 2015 16:38
Show Gist options
  • Save kos59125/5116257 to your computer and use it in GitHub Desktop.
Save kos59125/5116257 to your computer and use it in GitHub Desktop.
open System
type Foo = { Field : int }
let random = Random ()
let hasDuplicate keySelector =
let adjacent = Seq.windowed 2 >> Seq.map (function | [| x; y |] -> x, y | _ -> failwith "invalid")
Seq.scan (fun set value -> Set.add (keySelector value) set) Set.empty
>> adjacent
>> Seq.exists (fun (x, y) -> Set.count x = Set.count y)
Seq.initInfinite (fun _ -> { Field = random.Next (1000) })
//|> Seq.take 50 // 適当に小さな値を入れたら全部違う値になる気がする
|> hasDuplicate (fun foo -> foo.Field)
|> printfn "%b"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment