-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If a source has no elements then elements from an `alternative` source are emitted to the returned channel. If this source is failed then failure is passed to the returned channel. Examples: Source.fromValues(1).orElse(Source.fromValues(2, 3)).toList // List(1) Source.empty.orElse(Source.fromValues(2, 3)).toList // List(2, 3) Closes #37.
- Loading branch information
1 parent
efd3b9a
commit cbfbfd0
Showing
2 changed files
with
50 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
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,22 @@ | ||
package ox.channels | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import ox.* | ||
|
||
class SourceOpsOrElseTest extends AnyFlatSpec with Matchers { | ||
behavior of "SourceOps.orElse" | ||
|
||
it should "emit elements only from the original source when it is not empty" in supervised { | ||
Source.fromValues(1).orElse(Source.fromValues(2, 3)).toList shouldBe List(1) | ||
} | ||
|
||
it should "emit elements only from the alternative source when the original source is empty" in supervised { | ||
Source.empty.orElse(Source.fromValues(2, 3)).toList shouldBe List(2, 3) | ||
} | ||
|
||
it should "return failed source when the original source is failed" in supervised { | ||
val failure = new RuntimeException() | ||
Source.failed(failure).orElse(Source.fromValues(2, 3)).receive() shouldBe ChannelClosed.Error(Some(failure)) | ||
} | ||
} |