Skip to content

Commit

Permalink
Improved the README
Browse files Browse the repository at this point in the history
Signed-off-by: Uberto Barbini <[email protected]>
  • Loading branch information
uberto committed Jul 14, 2023
1 parent d5e9578 commit 8cec7be
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions kondor-mongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Kondor Json library.
## Key Features

- Strongly typed MongoDB collection handling
- Composition of MongoDB operations using Kleisli arrows
- Execution of composed operations in a monadic context, yielding a functional pipeline for data handling
- Simple and straightforward API for CRUD operations
- Full control over error handling
Expand Down Expand Up @@ -102,9 +101,10 @@ val cleanUp: MongoReader<Unit> = mongoOperation {
}
```

### Kleisli Composition
### Database Operation Composition

The Kleisli arrows allow you to compose your operations easily:
Since each operation on database is function returning a context, it's possible to easily compose them to create complex
operations:

```kotlin
@Test
Expand All @@ -121,23 +121,11 @@ fun `add and query doc safely`() {
In the above example, we compose the `cleanUp`, `docWriter`, and `docQuery` operations into a single operation using
the `+` operator.

You can also use the `bind` function to chain operations, and execute different operations based on the result of the
previous operation:
Technically speaking, if you really want to know, each database operation returns a `Reader` monad and we are composing
them using Kleisli arrows.

```kotlin
@Test
fun `operate on results`() {
val docIndex = Random.nextInt(100)

val myDoc = onMongo(
hundredDocWriter
.bind { docQuery(docIndex) }
.transformIfNotNull(::extractInfo)
).failIfNull { NotFoundError("The doc $docIndex is not present!") }
.expectSuccess()
expectThat(myDoc).contains(docIndex.toString())
}
```
But names are not important, what's nice with this approach is that it allows to easily reuse and test operation on
database without mixing the business logic with the database infrastructure details.

## ToDo

Expand Down

0 comments on commit 8cec7be

Please sign in to comment.