-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced the 'ensure' and 'ensureNotNull' functions
- Loading branch information
Showing
3 changed files
with
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
package in.rcard.raise4s | ||
|
||
/** Runs a computation `block` using [[Raise]], and return its outcome as [[Either]]. | ||
* - [[Right]] represents success, | ||
* - [[Left]] represents logical failure. | ||
* | ||
* This function re-throws any exceptions thrown within the [[Raise]] block. | ||
* | ||
* @param block A computation that can raise errors of type `Error` | ||
* @tparam A The type of the value returned by the computation | ||
* @tparam Error The type of the logical error that can be raised by the computation | ||
* @return An [[Either]] representing the outcome of the computation | ||
*/ | ||
def either[A, Error](block: Raise[Error] ?=> () => A): Either[Error, A] = | ||
fold(block, error => Left(error), value => Right(value)) |
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,12 @@ | ||
package in.rcard.raise4s | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class RaiseSpec extends AnyFlatSpec with Matchers { | ||
|
||
"ensureNotNull" should "return the value if it is not null" in { | ||
// TODO: Implement the test | ||
true should be(true) | ||
} | ||
} |