Skip to content

Commit

Permalink
Merge branch 'master' into update/sbt-jmh-0.4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
luksow authored Jul 3, 2024
2 parents 5a2ee67 + 5084a3e commit 6b6bf6b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.18, 2.13.12, 3.3.1]
scala: [2.12.19, 2.13.12, 3.3.3]
java: [temurin@8, temurin@17]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ newlines.topLevelStatementBlankLines = [
]
rewrite.rules = [SortImports, RedundantBraces]
runner.dialect = scala213
version=3.7.17
version=3.8.2
52 changes: 46 additions & 6 deletions README.md
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.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ val isDotty = Def.setting(CrossVersion.partialVersion(scalaVersion.value).exists

// Dependencies

val catsVersion = "2.10.0"
val catsVersion = "2.12.0"
val castsTestkitScalatestVersion = "2.1.5"

libraryDependencies ++= Seq(
Expand All @@ -18,7 +18,7 @@ libraryDependencies ++= (if (isDotty.value) Nil

// Multiple Scala versions support

val scala_2_12 = "2.12.18"
val scala_2_12 = "2.12.19"
val scala_2_13 = "2.13.12"
val dotty = "3.3.1"
val mainScalaVersion = scala_2_13
Expand Down
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6b6bf6b

Please sign in to comment.