Skip to content

Commit

Permalink
Turn TaskSeq.empty into a unit-function
Browse files Browse the repository at this point in the history
  • Loading branch information
abelbraaksma committed Oct 14, 2022
1 parent 09e1145 commit dbeb476
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Choose.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let ``ZHang timeout test`` () = task {
[<Fact>]
let ``TaskSeq-choose on an empty sequence`` () = task {
let! empty =
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.choose (fun _ -> Some 42)
|> TaskSeq.toListAsync

Expand All @@ -29,7 +29,7 @@ let ``TaskSeq-choose on an empty sequence`` () = task {
[<Fact>]
let ``TaskSeq-chooseAsync on an empty sequence`` () = task {
let! empty =
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.chooseAsync (fun _ -> task { return Some 42 })
|> TaskSeq.toListAsync

Expand Down
2 changes: 1 addition & 1 deletion src/FSharpy.TaskSeq.Test/TaskSeq.Collect.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ let ``TaskSeq-collectSeq with empty sequences`` () = task {

[<Fact>]
let ``TaskSeq-empty is empty`` () = task {
let! sq = TaskSeq.empty<string> |> TaskSeq.toSeqCachedAsync
let! sq = TaskSeq.empty<string> () |> TaskSeq.toSeqCachedAsync
Seq.isEmpty sq |> should be True
}
4 changes: 2 additions & 2 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Filter.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open FSharpy
[<Fact>]
let ``TaskSeq-filter on an empty sequence`` () = task {
let! empty =
TaskSeq.empty
TaskSeq.empty()
|> TaskSeq.filter ((=) 12)
|> TaskSeq.toListAsync

Expand All @@ -20,7 +20,7 @@ let ``TaskSeq-filter on an empty sequence`` () = task {
[<Fact>]
let ``TaskSeq-filterAsync on an empty sequence`` () = task {
let! empty =
TaskSeq.empty
TaskSeq.empty()
|> TaskSeq.filterAsync (fun x -> task { return x = 12 })
|> TaskSeq.toListAsync

Expand Down
8 changes: 4 additions & 4 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Find.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open System.Collections.Generic

[<Fact>]
let ``TaskSeq-find on an empty sequence raises KeyNotFoundException`` () = task {
fun () -> TaskSeq.empty |> TaskSeq.find ((=) 12) |> Task.ignore
fun () -> TaskSeq.empty () |> TaskSeq.find ((=) 12) |> Task.ignore
|> should throwAsyncExact typeof<KeyNotFoundException>
}

Expand All @@ -28,7 +28,7 @@ let ``TaskSeq-find on an empty sequence raises KeyNotFoundException - variant``
[<Fact>]
let ``TaskSeq-findAsync on an empty sequence raises KeyNotFoundException`` () = task {
fun () ->
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.findAsync (fun x -> task { return x = 12 })
|> Task.ignore
|> should throwAsyncExact typeof<KeyNotFoundException>
Expand Down Expand Up @@ -136,14 +136,14 @@ let ``TaskSeq-findAsync happy path last item of seq`` () = task {

[<Fact>]
let ``TaskSeq-tryFind on an empty sequence returns None`` () = task {
let! nothing = TaskSeq.empty |> TaskSeq.tryFind ((=) 12)
let! nothing = TaskSeq.empty () |> TaskSeq.tryFind ((=) 12)
nothing |> should be None'
}

[<Fact>]
let ``TaskSeq-tryFindAsync on an empty sequence returns None`` () = task {
let! nothing =
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.tryFindAsync (fun x -> task { return x = 12 })

nothing |> should be None'
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Fold.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let ``TaskSeq-foldAsync folds with every item`` () = task {
[<Fact>]
let ``TaskSeq-fold takes state on empty IAsyncEnumberable`` () = task {
let! empty =
TaskSeq.empty
TaskSeq.empty()
|> TaskSeq.fold (fun _ item -> char (item + 64)) '_'

empty |> should equal '_'
Expand All @@ -42,7 +42,7 @@ let ``TaskSeq-fold takes state on empty IAsyncEnumberable`` () = task {
[<Fact>]
let ``TaskSeq-foldAsync takes state on empty IAsyncEnumerable`` () = task {
let! alphabet =
TaskSeq.empty
TaskSeq.empty()
|> TaskSeq.foldAsync (fun _ item -> task { return char (item + 64) }) '_'

alphabet |> should equal '_'
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Head.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open FSharpy

[<Fact>]
let ``TaskSeq-head throws on empty sequences`` () = task {
fun () -> TaskSeq.empty<string> |> TaskSeq.head |> Task.ignore
fun () -> TaskSeq.empty<string> () |> TaskSeq.head |> Task.ignore
|> should throwAsyncExact typeof<ArgumentException>
}

Expand All @@ -22,7 +22,7 @@ let ``TaskSeq-head throws on empty sequences - variant`` () = task {

[<Fact>]
let ``TaskSeq-tryHead returns None on empty sequences`` () = task {
let! nothing = TaskSeq.empty<string> |> TaskSeq.tryHead
let! nothing = TaskSeq.empty<string> () |> TaskSeq.tryHead
nothing |> should be None'
}

Expand Down
19 changes: 11 additions & 8 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Item.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open FSharpy

[<Fact>]
let ``TaskSeq-item throws on empty sequences`` () = task {
fun () -> TaskSeq.empty<string> |> TaskSeq.item 0 |> Task.ignore
fun () -> TaskSeq.empty<string> () |> TaskSeq.item 0 |> Task.ignore
|> should throwAsyncExact typeof<ArgumentException>
}

Expand Down Expand Up @@ -57,22 +57,25 @@ let ``TaskSeq-item always throws with negative values`` () = task {
fun () -> make50 () |> TaskSeq.item Int32.MinValue |> Task.ignore
|> should throwAsyncExact typeof<ArgumentException>

fun () -> TaskSeq.empty<string> |> TaskSeq.item -1 |> Task.ignore
fun () -> TaskSeq.empty<string> () |> TaskSeq.item -1 |> Task.ignore
|> should throwAsyncExact typeof<ArgumentException>

fun () -> TaskSeq.empty<string> |> TaskSeq.item -10000 |> Task.ignore
fun () ->
TaskSeq.empty<string> ()
|> TaskSeq.item -10000
|> Task.ignore
|> should throwAsyncExact typeof<ArgumentException>

fun () ->
TaskSeq.empty<string>
TaskSeq.empty<string> ()
|> TaskSeq.item Int32.MinValue
|> Task.ignore
|> should throwAsyncExact typeof<ArgumentException>
}

[<Fact>]
let ``TaskSeq-tryItem returns None on empty sequences`` () = task {
let! nothing = TaskSeq.empty<string> |> TaskSeq.tryItem 0
let! nothing = TaskSeq.empty<string> () |> TaskSeq.tryItem 0
nothing |> should be None'
}

Expand Down Expand Up @@ -119,13 +122,13 @@ let ``TaskSeq-tryItem returns None throws with negative values`` () = task {
let! nothing = make50 () |> TaskSeq.tryItem Int32.MinValue
nothing |> should be None'

let! nothing = TaskSeq.empty<string> |> TaskSeq.tryItem -1
let! nothing = TaskSeq.empty<string> () |> TaskSeq.tryItem -1
nothing |> should be None'

let! nothing = TaskSeq.empty<string> |> TaskSeq.tryItem -10000
let! nothing = TaskSeq.empty<string> () |> TaskSeq.tryItem -10000
nothing |> should be None'

let! nothing = TaskSeq.empty<string> |> TaskSeq.tryItem Int32.MinValue
let! nothing = TaskSeq.empty<string> () |> TaskSeq.tryItem Int32.MinValue
nothing |> should be None'
}

Expand Down
4 changes: 2 additions & 2 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Last.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open FSharpy

[<Fact>]
let ``TaskSeq-last throws on empty sequences`` () = task {
fun () -> TaskSeq.empty<string> |> TaskSeq.last |> Task.ignore
fun () -> TaskSeq.empty<string> () |> TaskSeq.last |> Task.ignore
|> should throwAsyncExact typeof<ArgumentException>
}

Expand All @@ -22,7 +22,7 @@ let ``TaskSeq-last throws on empty sequences - variant`` () = task {

[<Fact>]
let ``TaskSeq-tryLast returns None on empty sequences`` () = task {
let! nothing = TaskSeq.empty<string> |> TaskSeq.tryLast
let! nothing = TaskSeq.empty<string> () |> TaskSeq.tryLast
nothing |> should be None'
}

Expand Down
8 changes: 4 additions & 4 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Pick.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open FSharpy
[<Fact>]
let ``TaskSeq-pick on an empty sequence raises KeyNotFoundException`` () = task {
fun () ->
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.pick (fun x -> if x = 12 then Some x else None)
|> Task.ignore
|> should throwAsyncExact typeof<KeyNotFoundException>
Expand All @@ -36,7 +36,7 @@ let ``TaskSeq-pick on an empty sequence raises KeyNotFoundException - variant``
[<Fact>]
let ``TaskSeq-pickAsync on an empty sequence raises KeyNotFoundException`` () = task {
fun () ->
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.pickAsync (fun x -> task { return if x = 12 then Some x else None })
|> Task.ignore
|> should throwAsyncExact typeof<KeyNotFoundException>
Expand Down Expand Up @@ -145,7 +145,7 @@ let ``TaskSeq-pickAsync happy path last item of seq`` () = task {
[<Fact>]
let ``TaskSeq-tryPick on an empty sequence returns None`` () = task {
let! nothing =
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.tryPick (fun x -> if x = 12 then Some x else None)

nothing |> should be None'
Expand All @@ -154,7 +154,7 @@ let ``TaskSeq-tryPick on an empty sequence returns None`` () = task {
[<Fact>]
let ``TaskSeq-tryPickAsync on an empty sequence returns None`` () = task {
let! nothing =
TaskSeq.empty
TaskSeq.empty ()
|> TaskSeq.tryPickAsync (fun x -> task { return if x = 12 then Some x else None })

nothing |> should be None'
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpy.TaskSeq.Test/TaskSeq.Tests.CE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ let ``CE taskSeq with nested deeply yield! perf test 8521 nested tasks`` () = ta
for i in 0..2 do
yield! createTasks 2

yield! TaskSeq.empty
yield! TaskSeq.empty()
}

let! data = tskSeq |> TaskSeq.toListAsync
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpy.TaskSeq.Test/TaskSeq.Tests.Other.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ open FSharpy

[<Fact>]
let ``TaskSeq-empty returns an empty sequence`` () = task {
let! sq = TaskSeq.empty<string> |> TaskSeq.toSeqCachedAsync
let! sq = TaskSeq.empty<string> () |> TaskSeq.toSeqCachedAsync
Seq.isEmpty sq |> should be True
Seq.length sq |> should equal 0
}

[<Fact>]
let ``TaskSeq-isEmpty returns true for empty`` () = task {
let! isEmpty = TaskSeq.empty<string> |> TaskSeq.isEmpty
let! isEmpty = TaskSeq.empty<string> () |> TaskSeq.isEmpty
isEmpty |> should be True
}

Expand Down
2 changes: 1 addition & 1 deletion src/FSharpy.TaskSeq/TaskSeq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module TaskSeq =
// Just for convenience
module Internal = TaskSeqInternal

let empty<'T> = taskSeq {
let empty<'T> () = taskSeq {
for c: 'T in [] do
yield c
}
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpy.TaskSeq/TaskSeq.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module TaskSeq =
open FSharpy.TaskSeqBuilders

/// Initialize an empty taskSeq.
val empty<'T> : taskSeq<'T>
val empty<'T> : unit -> taskSeq<'T>

/// <summary>
/// Returns <see cref="true" /> if the task sequence contains no elements, <see cref="false" /> otherwise.
Expand Down

0 comments on commit dbeb476

Please sign in to comment.