-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drops elements from the source as long as the predicate is satisfied. Note the predicate fails subsequent elements are no longer dropped even if they could still satisfy it. Source.empty[Int].dropWhile(_ > 3).toList // List() Source.fromValues(1, 2, 3).dropWhile(_ < 3).toList // List(3) Source.fromValues(1, 2, 1).dropWhile(_ < 2).toList // List(2, 1)
- Loading branch information
1 parent
ea8a9c3
commit b7b1702
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/test/scala/ox/channels/SourceOpsDropWhileTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ox.channels | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import ox.* | ||
|
||
class SourceOpsDropWhileTest extends AnyFlatSpec with Matchers { | ||
behavior of "Source.drop" | ||
|
||
it should "not drop from the empty source" in scoped { | ||
val s = Source.empty[Int] | ||
s.dropWhile(_ > 0).toList shouldBe List.empty | ||
} | ||
|
||
it should "drop elements from the source while predicate is true" in scoped { | ||
val s = Source.fromValues(1, 2, 3) | ||
s.dropWhile(_ < 3).toList shouldBe List(3) | ||
} | ||
|
||
it should "drop elements from the source until predicate is true and then emit subsequent ones" in scoped { | ||
val s = Source.fromValues(1, 2, 3, 2) | ||
s.dropWhile(_ < 3).toList shouldBe List(3, 2) | ||
} | ||
|
||
it should "not drop elements from the source if predicate is false" in scoped { | ||
val s = Source.fromValues(1, 2, 3) | ||
s.dropWhile(_ > 3).toList shouldBe List(1, 2, 3) | ||
} | ||
|
||
it should "not drop elements from the source when predicate is false for first or more elements" in scoped { | ||
val s = Source.fromValues(1, 4, 5) | ||
s.dropWhile(_ > 3).toList shouldBe List(1, 4, 5) | ||
} | ||
} |