Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/FSharpx.Collections/LazyList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module LazyList =
lzy(fun () -> (consc x (lzy(fun () -> (force(l()))))))

let consLazy x (l: Lazy<LazyList<'T>>) =
lzy(fun () -> consc x l.Value)
notlazy(CellCons(x, lzy(fun () -> force l.Value)))

let uncons(s: LazyList<'T>) = s.Uncons

Expand Down
12 changes: 11 additions & 1 deletion tests/FSharpx.Collections.Tests/LazyListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,17 @@ module LazyList =

test "consLazy lazy divergence" {
// tail is not evaluated unless the tail is consumed
Expect.isTrue "consLazy divergence" (let _ = LazyList.consLazy 1 (lazy (failwith "diverge")) in true)
let mutable tailForced = false

let tail =
lazy
(tailForced <- true
LazyList.ofList [ 2; 3 ])

let ll = LazyList.consLazy 1 tail
Expect.isFalse "consLazy divergence: construction should not force the tail" tailForced
let _ = LazyList.head ll
Expect.isFalse "consLazy divergence: head should not force the tail" tailForced
}

test "consLazy infinite" {
Expand Down