Skip to content

Instantly share code, notes, and snippets.

@mnzk
Created December 6, 2011 11:24
Show Gist options
  • Save mnzk/1437855 to your computer and use it in GitHub Desktop.
Save mnzk/1437855 to your computer and use it in GitHub Desktop.
LazyList
// see also. https://gist.github.com/1430157
open Microsoft.FSharp.Collections
let distanceOfSameValueElements xs =
let rec loop i dict xs =
let x = LazyList.head xs
match Map.tryFind x dict with
| None -> loop (i + 1) (Map.add x i dict) (LazyList.tail xs)
| Some j -> i - j
loop 0 Map.empty (LazyList.ofSeq xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment