Skip to content

Commit

Permalink
polished content v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Krever committed Oct 8, 2024
1 parent 4adc614 commit 78ad30f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Binary file not shown.
39 changes: 24 additions & 15 deletions 2024-10-art-of-scala/slides.html
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ <h2>Higher-Kinded <br/> Data</h2>

# Cool?

[TODO some funny pic]
<img src="resources/cool-flork-meme-vector-illustration_622487-2016.avif">

----

Expand Down Expand Up @@ -401,8 +401,6 @@ <h2>Higher-Kinded <br/> Data</h2>

### Rule conditions

<pre style="width: fit-content"><code class="hljs scala">Input[[t] =>> Expr[t => Boolean]]</code></pre>

```scala [1-4|5-8|10]
object IsPositive extends Expr[Int => Boolean] {
def evaluate: Int => Boolean = _ > 0
Expand All @@ -421,6 +419,8 @@ <h2>Higher-Kinded <br/> Data</h2>

### Decision Input

Values passed during evaluation

<pre style="width: fit-content"><code class="hljs scala">Input[[t] =>> t]</code></pre>

```scala [3|4|6]
Expand Down Expand Up @@ -556,7 +556,9 @@ <h2>Higher-Kinded <br/> Data</h2>
```scala
def pure[A[_]](f: [t] => () => A[t]): Data[A]
```
```scala [4-6]
<div class="fragment">

```scala [|4-6]
object Rule {
def default[Input[_[_]]: HKD, Output[_[_]]: HKD](output: Output[OutputValue]): Rule[Input, Output] = {
Rule(
Expand All @@ -569,6 +571,8 @@ <h2>Higher-Kinded <br/> Data</h2>
}
```

</div>

++++


Expand All @@ -580,7 +584,9 @@ <h2>Higher-Kinded <br/> Data</h2>
def mapK[B[_]](f: [t] => A[t] => B[t]): Data[B]
}
```
```scala [3,6]
<div class="fragment">

```scala [|3|6]
class Rule[..., Output[_[_]]: HKD](...) {
def evaluateOutput(): Output[Value] = {
output.mapK([t] => expr => expr.evaluate)
Expand All @@ -591,33 +597,36 @@ <h2>Higher-Kinded <br/> Data</h2>
}
```

</div>


++++


### `HKD.map2`

Merge two objects field by field
```scala
```scala [|2,3|5]
def map2[A[_], B[_], C[_]](
dataA: Data[A],
dataB: Data[B]
)(
f: [t] => (A[t], B[t]) => C[t],
): Data[C]
```
```scala [3-6]
<div class="fragment">

```scala [2|3-6]
class Rule[..., Output[_[_]]: HKD](...) {
def evaluate(in: Input[Value]) = {
val evaluated: Input[Const[Boolean]] =
HKD.map2(matching, in)(
[t] => (expr, value) => expr.evaluate(value)
)
...
}
def evaluate(in: Input[Value]): Input[Const[Boolean]] =
HKD.map2(matching, in)(
[t] => (expr, value) => expr.evaluate(value)
)
}
```

</div>

++++


Expand Down Expand Up @@ -754,7 +763,7 @@ <h2>Higher-Kinded <br/> Data</h2>

```scala
// Scala 3
val foo: Context ?=> Int => [A]
val foo: Context ?=> Int => String

// Scala 2
def foo(implicit ctx: Context): Int
Expand Down

0 comments on commit 78ad30f

Please sign in to comment.