-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into update/sbt-jmh-0.4.7
- Loading branch information
Showing
6 changed files
with
53 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Scala Steward: Reformat with scalafmt 3.7.17 | ||
7c6966fbfe8e67006302d992d51bef38713be851 | ||
|
||
# Scala Steward: Reformat with scalafmt 3.8.0 | ||
17c83ae6a8cc70e0b0ff8b5cc18975a37166a945 |
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
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,13 +1,53 @@ | ||
# sealed-monad | ||
|
||
## Scala library for nice for-comprehension-style error handling | ||
|
||
[![Maven Central](https://img.shields.io/maven-central/v/pl.iterators/sealed-monad_2.13.svg)]() | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/theiterators/sealed-monad/master/COPYING) | ||
[![Build Status](https://travis-ci.org/theiterators/sealed-monad.svg?branch=master)](https://travis-ci.org/theiterators/sealed-monad) | ||
[![GitHub license](https://img.shields.io/badge/license-Apache2.0-blue.svg)](https://raw.githubusercontent.com/theiterators/sealed-monad/master/COPYING) | ||
[![sealed-monad Scala version support](https://index.scala-lang.org/theiterators/sealed-monad/sealed-monad/latest-by-scala-version.svg)](https://index.scala-lang.org/theiterators/sealed-monad/sealed-monad) | ||
![logo](https://raw.githubusercontent.com/theiterators/sealed-monad/master/logo.png) | ||
|
||
### Documentation | ||
Scala library for nice business logic oriented, for-comprehension-style error handling. Write logic that even your manager can understand! | ||
|
||
Or in more technical terms, think of EitherT on steroids, with more human-readable method names. | ||
|
||
## Installation | ||
|
||
Add the following to your `build.sbt`: | ||
|
||
```scala | ||
libraryDependencies += "pl.iterators" %% "sealed-monad" % "1.3.0" | ||
``` | ||
|
||
Available for Scala 2.12.x, 2.13.x and 3.x. | ||
|
||
## Usage | ||
|
||
```scala | ||
def createTodo(userId: UUID, organizationId: UUID, request: CreateTodoRequest): IO[CreateTodoResponse] = { | ||
(for { | ||
user <- userRepository | ||
.find(userId) // IO[Option[User]] | ||
.valueOr(CreateTodoResponse.UserNotFound) // extracts User or returns UserNotFound | ||
_ <- organizationRepository | ||
.findFor(userId) // IO[Option[Organization]] | ||
.valueOr(CreateTodoResponse.UserNotInOrganization) // extracts Organization or returns UserNotInOrganization | ||
.ensure(_.canCreateTodos(user), CreateTodoResponse.UserNotAllowedToCreateTodos) // checks if user can create todos or returns UserNotAllowedToCreateTodos | ||
_ <- todoRepository | ||
.find(request.title) // IO[Option[Todo]] | ||
.ensure(_.isEmpty, CreateTodoResponse.TodoAlreadyExists) // checks if todo already exists or returns TodoAlreadyExists | ||
_ <- Todo | ||
.from(request) | ||
.pure[IO] // IO[Todo] | ||
.ensure(_.title.nonEmpty, CreateTodoResponse.TodoTitleEmpty) // checks if todo title is non-empty or returns TodoTitleEmpty | ||
todo <- todoRepository.insert(Todo(UUID.randomUUID(), request.title)).seal // todo created! | ||
} yield CreateTodoResponse.Created(todo)).run // compile to IO[CreateTodoResponse] | ||
} | ||
``` | ||
|
||
## Documentation | ||
|
||
Please refer to the [docs](https://theiterators.github.io/sealed-monad) site. | ||
|
||
![logo](https://raw.githubusercontent.com/theiterators/sealed-monad/master/logo.png) | ||
|
||
## License | ||
|
||
This project is licensed under the Apache 2.0 License - see the [LICENSE](https://github.com/theiterators/sealed-monad/blob/master/LICENSE) file for details. |
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