Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Sep 23, 2023
1 parent 47ed2b7 commit 5150349
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Drawing inspiration from [ZIO](https://zio.dev/)'s [effect rotation](https://deg
1. [The `>` type](#the--type)
2. [Effect widening](#effect-widening)
3. [Using effects](#using-effects)
3. [Direct Syntax](#direct-syntax)
4. [Core Effects](#core-effects)
1. [Aborts: Short Circuiting](#aborts-short-circuiting)
2. [IOs: Side Effects](#ios-side-effects)
Expand Down Expand Up @@ -219,8 +220,7 @@ assert(triesFirst(Tries.get(Failure(ex))) == Some(Failure(ex)))

Kyo provides direct syntax for a more intuitive and concise way to express computations, especially when dealing with multiple effects. This syntax leverages two primary constructs: `defer` and `await`.

1. `defer`: This construct is used to define a computation. It acts as a container or a block within which computations are expressed and sequenced.
2. `await`: Within the defer block, the `await` construct is used to "pause" the computation and wait for a value from another computation. It essentially allows the current computation to yield control until the awaited computation produces a result, after which the original computation resumes.
The `defer` construct serves as a container for sequencing computations. Within this container, the `await` construct simplifies the handling of effectful computations. Essentially, `await` is a syntactic sugar for the `map` function, allowing developers to directly access values from computations without the need for repetitive `map` chaining. This makes the code more linear and intuitive.

```scala
import kyo.direct._
Expand All @@ -245,11 +245,9 @@ val b: String > (Tries with Options) =
}
```

> Note: In the above example, the await method is used to extract values from computations. Specifically, `await(Options.get(Some("hello")))` takes a computation of type `String > Options` and returns a `String`, while `await(Tries.get(Try("world")))` takes a computation of type `String > Tries` and also returns a `String`.
The transformation translates the `defer` and `await` constructs, virtualizing control flow to align with the mechanics of effectful computations. By analyzing the code, the macro restructures it according to identified patterns. It modifies value definitions, conditional branches, loops, and pattern matching to fit the requirements of effectful compurations expressed in terms of `map`.

The use of `await` within the defer `block` provides a syntax sugar that simplifies the expression of effectful computations. Under the hood, the direct macro rewrites the computation in terms of map, allowing developers to work with effectful computations as if they were pure values, seamlessly integrating them into the flow of the program.

The direct syntax emphasizes "effectful hygiene" to ensure that computations are properly sequenced and managed. Within a `defer` block, any computation of the `>` type must be encapsulated by an `await` block. This mechanism guarantees that all effectful computations are explicitly awaited, eliminating the risks of inadvertently overlooking effects or misordering operations.
For added reliability, the direct syntax prioritizes effectful hygiene, ensuring computations are orderly and well-managed. Within a defer block, computations of the > type must be enclosed by an await block. This approach ensures all effectful computations are explicitly processed, reducing the potential for missed effects or operation misalignment.

```scala
import kyo.ios._
Expand Down

0 comments on commit 5150349

Please sign in to comment.