Skip to content

Commit

Permalink
polished content v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Krever committed Oct 2, 2024
1 parent 2effcf3 commit b258d1d
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions 2024-10-art-of-scala/slides.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2>Higher-Kinded <br/> Data</h2>

### Business logic

Approval process
Pull request approval process

<small>
<ul>
Expand Down Expand Up @@ -193,28 +193,32 @@ <h2>Higher-Kinded <br/> Data</h2>

```scala
val rule4 = Rule.default(
Output(
allowMerging = false,
notifyUnusualAction = false
),
Output(
allowMerging = false,
notifyUnusualAction = false
)
)
```

++++

### Decision table

```scala [3|4|5]
```scala [1|3|4|5]
val decisionTable: DecisionTable[Input, Output, HitPolicy.First] =
DecisionTable(
Seq(rule1, rule2, rule3, rule4),
"PullRequestDecision",
HitPolicy.First
)
```

++++

### Detour: `HitPolicy`

Strategy defining what to do with triggered rules outputs

* unique
* first
* combine
Expand Down Expand Up @@ -293,6 +297,12 @@ <h2>Higher-Kinded <br/> Data</h2>
== Output(true,false)
```

++++

# Cool?

[TODO some funny pic]

----

<span class="breadcrumb-data">Decisions4s</span>
Expand All @@ -316,7 +326,11 @@ <h2>Higher-Kinded <br/> Data</h2>

### Difference from tagless final?

Higher-kinded data is actually useful
<pre style="width: fit-content"><code class="hljs scala">trait Foo[F[_]]{
def a: F[Int]
}</code></pre>

<span class="fragment">Higher-kinded data is actually useful</span>

++++

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

```scala
trait Expr[T] {
def evaluate: T
def render: String
def evaluate: T
def render: String
}
```

Expand All @@ -377,8 +391,8 @@ <h2>Higher-Kinded <br/> Data</h2>

// Input[UnaryTest]
case class InlinedInput(
a: Expr[Int => Boolean],
b: Expr[String => Boolean]
a: Expr[Int => Boolean],
b: Expr[String => Boolean]
)
```

Expand All @@ -389,7 +403,7 @@ <h2>Higher-Kinded <br/> Data</h2>

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

```scala [1-4|5-8|10|12]
```scala [1-4|5-8|10]
object IsPositive extends Expr[Int => Boolean] {
def evaluate: Int => Boolean = _ > 0
def render: String = "isPositive"
Expand Down Expand Up @@ -439,12 +453,12 @@ <h2>Higher-Kinded <br/> Data</h2>
type RuleOutput = Output[Expr]

case class Literal[T](value: T) extends Expr[T] {
def evaluate: T = value
def render: String = value.toString
def evaluate: T = value
def render: String = value.toString
}

val output: RuleOutput =
Input[Expr](a = Literal(1), b = Literal("hi"))
Input[Expr](a = Literal(1), b = Literal("hi"))
```

++++
Expand All @@ -465,7 +479,7 @@ <h2>Higher-Kinded <br/> Data</h2>
```scala [3|5-6|7-8|9-10|11-12|13-14]
case class Input[F[_]](a: F[Int], b: F[String])

type Const[T] = [t] =>> T
type Const[A] = [t] =>> A

type FieldNames = Input[Const[String]]
// Input("a", "b")
Expand All @@ -485,9 +499,9 @@ <h2>Higher-Kinded <br/> Data</h2>

### Can we just use maps?

- hard to implement heterogeneous ones
- can't ensure key set
- no IDE support
- hard to implement heterogeneous ones <!-- .element: class="fragment fade-in-then-semi-out " -->
- can't ensure the key set <!-- .element: class="fragment fade-in-then-semi-out " -->
- no IDE support <!-- .element: class="fragment fade-in-then-semi-out " -->

++++

Expand Down Expand Up @@ -618,9 +632,13 @@ <h2>Higher-Kinded <br/> Data</h2>

### Recursion is hard

++++

### Recursion is hard

To wrap or not to wrap?

```scala
```scala [3-5]
case class Foo[F[_]](a: F[Int])

case class Bar1[F[_]](b: Foo[F])
Expand Down Expand Up @@ -652,7 +670,7 @@ <h2>Higher-Kinded <br/> Data</h2>

### Recursion is hard

Storing metadata is harder
Storing metadata is more complicated

```scala
case class Meta[T](
Expand All @@ -662,6 +680,7 @@ <h2>Higher-Kinded <br/> Data</h2>
)
val meta: Input[Meta]
```
<span style="font-size: 0.7em;color: gray">Works only with wrapping</span>

----

Expand All @@ -683,7 +702,7 @@ <h2>Higher-Kinded <br/> Data</h2>
// Scala 3
[t] =>> Either[Int, t]
// Scala 2
{type X[t] = Either[Int, t]})#X
({ type X[t] = Either[Int, t] })#X
// Scala 2 with kind-projector
Lambda[t => Either[Int, t]]
```
Expand Down Expand Up @@ -748,7 +767,7 @@ <h2>Higher-Kinded <br/> Data</h2>

### Context functions

```scala
```scala [1-4|6-9]
// grants access to the whole input
trait EvaluationContext[In[_[_]]] {
def wholeInput: In[Expr]
Expand All @@ -764,7 +783,7 @@ <h2>Higher-Kinded <br/> Data</h2>

### Context functions

```scala
```scala [7]
// syntax
def wholeInput[In[_[_]]](using ec: EvaluationContext[In]): In[Expr] =
ec.wholeInput
Expand Down

0 comments on commit b258d1d

Please sign in to comment.