diff --git a/.gitignore b/.gitignore index e34292a..c2f4f6b 100644 --- a/.gitignore +++ b/.gitignore @@ -47,81 +47,28 @@ buildNumber.properties # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - # CMake cmake-build-*/ -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - # File-based project format *.iws +# Build Server +.bsp + # IntelliJ out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ +.idea* # JIRA plugin atlassian-ide-plugin.xml -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - ### SBT template # Simple Build Tool # http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control diff --git a/README.md b/README.md index ca0ffe2..f1668a1 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ The `fold` function “consumes” the context, creating a concrete instance of There are other flavors of the `fold` function. So, please, be sure to check them in the documentation. -Please be aware that any exception thrown inside the `Raise[E]` context will bubble up and not be transformed automatically into a logical typed error. What if we want to convert the exception into a typed error? For example, we want to convert the `IllegalArgumentException` into a `UserNotFound`. Well, we can do it using a function called `$catch`: +Please be aware that any exception thrown inside the `Raise[E]` context will bubble up and not be transformed automatically into a logical typed error. What if we want to convert the exception into a typed error? For example, we want to convert the `IllegalArgumentException` into a `UserNotFound`. Well, we can do it using a function called `catching`: ```scala 3 def findUserByIdWithEx(id: String): User = @@ -110,12 +110,12 @@ def findUserByIdWithEx(id: String): User = val maybeUser: Either[Error, User] = Raise.either: - Raise.$catch[User](() => findUserByIdWithEx("42"), { + Raise.catching[User](() => findUserByIdWithEx("42"), { case _: IllegalArgumentException => Raise.raise(UserNotFound("42")) }) ``` -We will see the `either` function in a moment. As we can see, there’s nothing special with the `$catch` function. It just catches the exception and calls the catch lambda with the exception. The `$catch` function lets the fatal exception bubble up. +We will see the `either` function in a moment. As we can see, there’s nothing special with the `catching` function. It just catches the exception and calls the catch lambda with the exception. The `catching` function lets the fatal exception bubble up. It’s a different story if we want to recover or react to a typed error. In this case, we can use the `recover` function: @@ -172,15 +172,15 @@ val three = Raise.either { The `bind` function calls the `raise` function if the `Either` instance is a `Left`; otherwise, it returns the value wrapped by the `Right` instance. Despite the trivial logic implemented in the above example, it's a good example of how to compose functions that return an `Either[E, A]` using the Raise DSL without the use of any `flatMap` function. -We can do the same with `Try[A]` and `Option[A]` using the `$try` and `option` builders, respectively. Let's start with the `$try` builder. In this case, the only available type of error is `Throwable`: +We can do the same with `Try[A]` and `Option[A]` using the `asTry` and `option` builders, respectively. Let's start with the `asTry` builder. In this case, the only available type of error is `Throwable`: ```scala 3 val maybeUserWithTry: Try[User] = - Raise.$try: + Raise.asTry: findUserByIdWithEx("42") ``` -As you might guess, any fatal exception thrown inside the `$try` context will bubble up and not handled. +As you might guess, any fatal exception thrown inside the `asTry` context will bubble up and not handled. Last but not least, the `option` builder: diff --git a/src/main/scala/in/rcard/raise4s/Builders.scala b/src/main/scala/in/rcard/raise4s/Builders.scala index 6765649..3641b8f 100644 --- a/src/main/scala/in/rcard/raise4s/Builders.scala +++ b/src/main/scala/in/rcard/raise4s/Builders.scala @@ -31,7 +31,7 @@ object RaiseTryPredef: case Success(a) => a case Failure(e) => tryRaise.raise(e) -def $try[A](block: Raise[Throwable] ?=> A): Try[A] = +def asTry[A](block: Raise[Throwable] ?=> A): Try[A] = fold( { given tryRaise: Raise[Throwable] = new DefaultRaise() diff --git a/src/main/scala/in/rcard/raise4s/Raise.scala b/src/main/scala/in/rcard/raise4s/Raise.scala index eaba69c..292e0ba 100644 --- a/src/main/scala/in/rcard/raise4s/Raise.scala +++ b/src/main/scala/in/rcard/raise4s/Raise.scala @@ -171,7 +171,7 @@ object Raise { * *