September 2023
Intermediate to advanced
470 pages
11h 12m
English
It’s now time to put the monads to work on the database library we started before. Using the ContextReader we wrote in the previous chapter, we can now combine the read and write operations in the same transaction:
| | val listUpdater = readRow("myRowId") |
| | .transform { r-> r.copy(active = false) } |
| ① | .bind { r -> writeRow(r) } |
| | |
| ② | runInTransaction(listUpdater).expectSuccess() |
With the bind method, we’re able to make the writeRow call compile and work correctly without using a non-local return.
Until we run the ContextReader in a transaction, ContextReader is only maintaining a record of the operations we intend to carry out on the database, without performing them. All the actual database calls ...
Read now
Unlock full access