Skip to content
Draft
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
33 changes: 8 additions & 25 deletions src/FSharpx.Collections.Experimental/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Auto-Generated by FAKE; do not edit
namespace System

open System.Reflection
open System.Runtime.CompilerServices

Expand All @@ -15,27 +14,11 @@ open System.Runtime.CompilerServices
do ()

module internal AssemblyVersionInformation =
[<Literal>]
let AssemblyTitle = "FSharpx.Collections.Experimental"

[<Literal>]
let AssemblyProduct = "FSharpx.Collections"

[<Literal>]
let AssemblyDescription =
"FSharpx.Collections is a collection of datastructures for use with F# and C#."

[<Literal>]
let InternalsVisibleTo = "FSharpx.Collections.Tests"

[<Literal>]
let InternalsVisibleTo_1 = "FSharpx.Collections.Experimental.Tests"

[<Literal>]
let AssemblyVersion = "3.1.0"

[<Literal>]
let AssemblyFileVersion = "3.1.0"

[<Literal>]
let AssemblyConfiguration = "Release"
let [<Literal>] AssemblyTitle = "FSharpx.Collections.Experimental"
let [<Literal>] AssemblyProduct = "FSharpx.Collections"
let [<Literal>] AssemblyDescription = "FSharpx.Collections is a collection of datastructures for use with F# and C#."
let [<Literal>] InternalsVisibleTo = "FSharpx.Collections.Tests"
let [<Literal>] InternalsVisibleTo_1 = "FSharpx.Collections.Experimental.Tests"
let [<Literal>] AssemblyVersion = "3.1.0"
let [<Literal>] AssemblyFileVersion = "3.1.0"
let [<Literal>] AssemblyConfiguration = "Release"
33 changes: 8 additions & 25 deletions src/FSharpx.Collections/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Auto-Generated by FAKE; do not edit
namespace System

open System.Reflection
open System.Runtime.CompilerServices

Expand All @@ -15,27 +14,11 @@ open System.Runtime.CompilerServices
do ()

module internal AssemblyVersionInformation =
[<Literal>]
let AssemblyTitle = "FSharpx.Collections"

[<Literal>]
let AssemblyProduct = "FSharpx.Collections"

[<Literal>]
let AssemblyDescription =
"FSharpx.Collections is a collection of datastructures for use with F# and C#."

[<Literal>]
let InternalsVisibleTo = "FSharpx.Collections.Tests"

[<Literal>]
let InternalsVisibleTo_1 = "FSharpx.Collections.Experimental.Tests"

[<Literal>]
let AssemblyVersion = "3.1.0"

[<Literal>]
let AssemblyFileVersion = "3.1.0"

[<Literal>]
let AssemblyConfiguration = "Release"
let [<Literal>] AssemblyTitle = "FSharpx.Collections"
let [<Literal>] AssemblyProduct = "FSharpx.Collections"
let [<Literal>] AssemblyDescription = "FSharpx.Collections is a collection of datastructures for use with F# and C#."
let [<Literal>] InternalsVisibleTo = "FSharpx.Collections.Tests"
let [<Literal>] InternalsVisibleTo_1 = "FSharpx.Collections.Experimental.Tests"
let [<Literal>] AssemblyVersion = "3.1.0"
let [<Literal>] AssemblyFileVersion = "3.1.0"
let [<Literal>] AssemblyConfiguration = "Release"
1 change: 1 addition & 0 deletions src/FSharpx.Collections/FSharpx.Collections.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Compile Include="Infrastructure.fs" />
<Compile Include="LazyList.fsi" />
<Compile Include="LazyList.fs" />
<Compile Include="LazyListOperators.fs" />
<Compile Include="ResizeArray.fsi" />
<Compile Include="ResizeArray.fs" />
<Compile Include="Collections.fs" />
Expand Down
10 changes: 10 additions & 0 deletions src/FSharpx.Collections/LazyListOperators.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// Operators for working with LazyList.
/// This module is opened automatically when FSharpx.Collections is opened.
[<AutoOpen>]
module FSharpx.Collections.LazyListOperators

/// O(1). Returns a new LazyList with the given head and a lazy tail.
/// Infix operator alias for LazyList.consLazy.
/// Example: <c>let rec ones = 1 @@ lazy ones</c>
let inline (@@) (head: 'T) (tail: Lazy<LazyList<'T>>) : LazyList<'T> =
LazyList.consLazy head tail
31 changes: 31 additions & 0 deletions tests/FSharpx.Collections.Tests/LazyListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,37 @@ module LazyList =
Expect.equal "consLazy infinite" [ 1; 1; 1; 1; 1 ] (LazyList.take 5 ones |> LazyList.toList)
}

test "@@ head" {
let tail = lazy (LazyList.ofList [ 2; 3 ])
Expect.equal "@@ head" 1 (LazyList.head(1 @@ tail))
}

test "@@ toList" {
let tail = lazy (LazyList.ofList [ 2; 3 ])
Expect.equal "@@ toList" [ 1; 2; 3 ] (LazyList.toList(1 @@ tail))
}

test "@@ lazy divergence" {
// tail is not evaluated unless the tail is consumed
let mutable tailForced = false

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

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

test "@@ infinite" {
// build ones = 1 :: 1 :: ... using @@ operator
let rec ones: LazyList<int> = 1 @@ lazy ones
Expect.equal "@@ infinite" [ 1; 1; 1; 1; 1 ] (LazyList.take 5 ones |> LazyList.toList)
}

test "takedrop" {
Expect.equal "takedrop" [ 4; 5; 6 ]
<| LazyList.toList(LazyList.take 3 (LazyList.skip 4 nats))
Expand Down
15 changes: 15 additions & 0 deletions tests/fable/FSharpx.Collections.Tests/LazyList.test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@ let tests =
let xs = xs |> LazyList.tail |> LazyList.tail

Expect.equal (LazyList.tryHead xs) (Some 3) "should reach third element"
}

test "@@ head" {
let tail = lazy (LazyList.ofList [ 2; 3 ])
Expect.equal (LazyList.head(1 @@ tail)) 1 "@@ head"
}

test "@@ toList" {
let tail = lazy (LazyList.ofList [ 2; 3 ])
Expect.equal (LazyList.toList(1 @@ tail)) [ 1; 2; 3 ] "@@ toList"
}

test "@@ infinite" {
let rec ones: LazyList<int> = 1 @@ lazy ones
Expect.equal (LazyList.take 5 ones |> LazyList.toList) [ 1; 1; 1; 1; 1 ] "@@ infinite"
} ]