https://github.com/zalbia/zio-structure
Just learning how to structure ZIO programs
https://github.com/zalbia/zio-structure
functional-programming scala zio
Last synced: 20 days ago
JSON representation
Just learning how to structure ZIO programs
- Host: GitHub
- URL: https://github.com/zalbia/zio-structure
- Owner: zalbia
- License: mit
- Created: 2019-09-13T03:18:48.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-23T15:26:27.000Z (over 5 years ago)
- Last Synced: 2025-01-08T11:14:46.805Z (10 months ago)
- Topics: functional-programming, scala, zio
- Language: Scala
- Homepage:
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# zio-structure
Just another ZIO demo, with an emphasis on service-level transactions using
[zio-saga](https://github.com/VladKopanev/zio-saga). I have explored three
ways of doing this, namely:
- tagless-final encoding: which I found to be annoying, and realized later on
to have unprincipled, leaky abstractions because I was depending on the
repository implementation to do the transactions;
- plain old programming to an interface: didn't quite work out for me because
I've had to duplicate FooService code (not to mention leaky abstractions); and,
- zio-saga: which I just recently realized is the implementation with _actual_
service-level transactions and is purely encoded in the domain layer. This
is the domain-driven way to go!
## How to run
`sbt run`
There are three mains to choose from:
- `InMemoryMain` - Runs `Program` with an in-memory standard lib `Map` repository
- `SlickMain` - Runs `Program` with an in-memory Slick h2 repository
- `ParMain` - `ZStream`'s high-level concurrency demo, adding streams of `Long`s in single vs multi-threaded mode
## Service-level transactions
See [`mergeFoos`](https://github.com/zach-albia/zio-structure/blob/master/src/main/scala/domain/FooService.scala#L55) for an example.