Skip to content

Commit

Permalink
Added Stream.isEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
anirothan committed Apr 21, 2015
1 parent ef35fc6 commit 86ce3f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Streams.Core/Streams.fs
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,12 @@ module Stream =
match tryHead stream with
| Some value -> value
| None -> invalidArg "stream" "The stream was empty."


/// <summary>
/// Returs true if the stream is empty and false otherwise.
/// </summary>
/// <param name="stream">The input stream.</param>
/// <returns>true if the input stream is empty, false otherwise</returns>
let inline isEmpty (stream : Stream<'T>) : bool =
stream |> exists (fun _ -> true) |> not
8 changes: 8 additions & 0 deletions tests/Streams.Tests/StreamsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,11 @@
with :? System.ArgumentException -> None

Assert.AreEqual(y, x)).QuickCheckThrowOnFailure()

[<Test>]
member __.``isEmpty``() =
Spec.ForAny<int []>(fun (xs : int []) ->
let x = xs |> Stream.ofArray |> Stream.isEmpty
let y = xs |> Array.isEmpty

Assert.AreEqual(x, y)).QuickCheckThrowOnFailure()

0 comments on commit 86ce3f0

Please sign in to comment.