diff --git a/src/main/scala/in/rcard/raise4s/Raise.scala b/src/main/scala/in/rcard/raise4s/Raise.scala index 789ac53..9c0d80b 100644 --- a/src/main/scala/in/rcard/raise4s/Raise.scala +++ b/src/main/scala/in/rcard/raise4s/Raise.scala @@ -85,7 +85,7 @@ object Raise { *

Example

* {{{ * val actual: Int = fold( - * { ensureNotNull(null, () => "error") }, + * { ensureNotNull(null) { "error" } }, * error => 43, * value => 42 * ) @@ -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 diff --git a/src/test/scala/in/rcard/raise4s/RaiseSpec.scala b/src/test/scala/in/rcard/raise4s/RaiseSpec.scala index 4dab85b..8dcd2a8 100644 --- a/src/test/scala/in/rcard/raise4s/RaiseSpec.scala +++ b/src/test/scala/in/rcard/raise4s/RaiseSpec.scala @@ -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 ) @@ -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 )