Skip to content

Commit

Permalink
Currified the 'ensureNotNull' function
Browse files Browse the repository at this point in the history
  • Loading branch information
rcardin committed Apr 24, 2024
1 parent 6ee66c0 commit de82c65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/in/rcard/raise4s/Raise.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object Raise {
* <h2>Example</h2>
* {{{
* val actual: Int = fold(
* { ensureNotNull(null, () => "error") },
* { ensureNotNull(null) { "error" } },
* error => 43,
* value => 42
* )
Expand All @@ -105,8 +105,8 @@ object Raise {
* @return
* The value if it is not null
*/
def ensureNotNull[B, Error](value: B, raise: () => Error)(using r: Raise[Error]): B =
if value == null then r.raise(raise())
def ensureNotNull[B, Error](value: B)(raise: => Error)(using r: Raise[Error]): B =
if value == null then r.raise(raise)
else value

/** Execute the [[Raise]] context function resulting in `A` or any _logical error_ of type
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/in/rcard/raise4s/RaiseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RaiseSpec extends AnyFlatSpec with Matchers {

"ensureNotNull" should "return the value if it is not null" in {
val actual: Int = Raise.fold(
{ Raise.ensureNotNull(42, () => "error") },
{ Raise.ensureNotNull(42) { "error" } },
error => 43,
identity
)
Expand All @@ -35,7 +35,7 @@ class RaiseSpec extends AnyFlatSpec with Matchers {

it should "return the error if the value is null" in {
val actual: Int = Raise.fold(
{ Raise.ensureNotNull(null, () => "error") },
{ Raise.ensureNotNull(null) { "error" } },
error => 43,
value => 42
)
Expand Down

0 comments on commit de82c65

Please sign in to comment.