-
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.
Sends elements to the returned channel until predicate is satisfied. Note that if the predicate fails then subsequent elements are not longer taken even if they could still satisfy it. Example: Source.empty[Int].takeWhile(_ > 3).toList // List() Source.fromValues(1, 2, 3).takeWhile(_ < 3).toList // List(1, 2) Source.fromValues(3, 2, 1).takeWhile(_ < 3).toList // List()
- Loading branch information
1 parent
161557a
commit f9bd0b1
Showing
2 changed files
with
44 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
core/src/test/scala/ox/channels/SourceOpsTakeWhileTest.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,24 @@ | ||
package ox.channels | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import ox.* | ||
|
||
class SourceOpsTakeWhileTest extends AnyFlatSpec with Matchers { | ||
behavior of "Source.takeWhile" | ||
|
||
it should "not take from the empty source" in scoped { | ||
val s = Source.empty[Int] | ||
s.takeWhile(_ < 3).toList shouldBe List.empty | ||
} | ||
|
||
it should "take as long as predicate is satisfied" in scoped { | ||
val s = Source.fromValues(1, 2, 3) | ||
s.takeWhile(_ < 3).toList shouldBe List(1, 2) | ||
} | ||
|
||
it should "not take if predicate fails for first or more elements" in scoped { | ||
val s = Source.fromValues(3, 2, 1) | ||
s.takeWhile(_ < 3).toList shouldBe List() | ||
} | ||
} |