Skip to content

Commit

Permalink
deploy: 927a9bb
Browse files Browse the repository at this point in the history
  • Loading branch information
satorg committed Sep 4, 2024
1 parent 3994671 commit e3cc105
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
12 changes: 6 additions & 6 deletions datatypes/contt.html
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ <h1 id="contt" class="title">ContT</h1>
</span><span class="type-name">Succeeded</span><span>(</span><span class="identifier">user</span><span>.</span><span class="identifier">id</span><span>)
}
}
</span><span class="comment">// eval: Eval[UserUpdateResult] = cats.Later@68edb6dd</span></code></pre>
</span><span class="comment">// eval: Eval[UserUpdateResult] = cats.Later@4cbd426f</span></code></pre>
<p>Finally we can run the resulting <code>Eval</code> to actually execute the computation:</p>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="identifier">eval</span><span>.</span><span class="identifier">value</span><span>
</span><span class="comment">// Persisting updated user to the DB: User(100,Bob,150)
Expand All @@ -308,7 +308,7 @@ <h2 id="composition" class="section"><a class="anchor-link left" href="#composit
}
</span><span class="comment">// anotherComputation: ContT[Eval, UserUpdateResult, Map[String, String]] = FromFn(
// runAndThen = Single(
// f = cats.data.ContT$$Lambda$14380/0x00007f397f661bb0@32a2b5ea,
// f = cats.data.ContT$$Lambda$14291/0x00007f1ed0665a60@3314d690,
// index = 0
// )
// )
Expand All @@ -319,7 +319,7 @@ <h2 id="composition" class="section"><a class="anchor-link left" href="#composit
</span><span class="type-name">Succeeded</span><span>(</span><span class="identifier">userFields</span><span>(</span><span class="string-literal">&quot;id&quot;</span><span>).</span><span class="identifier">toInt</span><span>)
}
}
</span><span class="comment">// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@6435b180
</span><span class="comment">// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@23e959ca
</span><span>
</span><span class="identifier">anotherEval</span><span>.</span><span class="identifier">value</span><span>
</span><span class="comment">// Persisting these fields to the DB: Map(id -&gt; 100, name -&gt; Bob, age -&gt; 150)
Expand All @@ -336,7 +336,7 @@ <h2 id="composition" class="section"><a class="anchor-link left" href="#composit
}
</span><span class="comment">// updateUserModel: ContT[Eval, UserUpdateResult, User] = FromFn(
// runAndThen = Single(
// f = cats.data.ContT$$Lambda$14380/0x00007f397f661bb0@9a086f1,
// f = cats.data.ContT$$Lambda$14291/0x00007f1ed0665a60@64870a49,
// index = 0
// )
// )
Expand Down Expand Up @@ -370,7 +370,7 @@ <h2 id="composition" class="section"><a class="anchor-link left" href="#composit
</span><span class="identifier">updateUserModel</span><span> </span><span class="identifier">flatMap</span><span> </span><span class="identifier">persistToDb</span><span> </span><span class="identifier">flatMap</span><span> </span><span class="identifier">publishEvent</span><span>
</span><span class="comment">// chainOfContinuations: ContT[Eval, UserUpdateResult, UserUpdateResult] = FromFn(
// runAndThen = Single(
// f = cats.data.ContT$$Lambda$14384/0x00007f397f662538@6c75cdce,
// f = cats.data.ContT$$Lambda$14295/0x00007f1ed06663e8@231df336,
// index = 0
// )
// )
Expand All @@ -381,7 +381,7 @@ <h2 id="composition" class="section"><a class="anchor-link left" href="#composit
</span><span class="identifier">finalResult</span><span>
}
}
</span><span class="comment">// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@d9681f0
</span><span class="comment">// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@eb03d68
</span><span>
</span><span class="identifier">eval</span><span>.</span><span class="identifier">value</span><span>
</span><span class="comment">// Updated user model
Expand Down
4 changes: 2 additions & 2 deletions datatypes/eval.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ <h4 id="eval-later" class="section"><a class="anchor-link left" href="#eval-late
</span><span class="identifier">println</span><span>(</span><span class="string-literal">&quot;Running expensive calculation...&quot;</span><span>)
</span><span class="number-literal">1</span><span> + </span><span class="number-literal">2</span><span> * </span><span class="number-literal">3</span><span>
}
</span><span class="comment">// lazyEval: Eval[Int] = cats.Later@755eab50
</span><span class="comment">// lazyEval: Eval[Int] = cats.Later@62ca7846
</span><span>
</span><span class="identifier">lazyEval</span><span>.</span><span class="identifier">value</span><span>
</span><span class="comment">// Running expensive calculation...
Expand All @@ -276,7 +276,7 @@ <h4 id="eval-always" class="section"><a class="anchor-link left" href="#eval-alw
</span><span class="identifier">println</span><span>(</span><span class="string-literal">&quot;Running expensive calculation...&quot;</span><span>)
</span><span class="number-literal">1</span><span> + </span><span class="number-literal">2</span><span> * </span><span class="number-literal">3</span><span>
}
</span><span class="comment">// always: Eval[Int] = cats.Always@1a6a8f7
</span><span class="comment">// always: Eval[Int] = cats.Always@1625ea44
</span><span>
</span><span class="identifier">always</span><span>.</span><span class="identifier">value</span><span>
</span><span class="comment">// Running expensive calculation...
Expand Down
2 changes: 1 addition & 1 deletion datatypes/freeapplicative.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ <h2 id="example" class="section"><a class="anchor-link left" href="#example"><i
}
}</span></code></pre>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">validator</span><span> = </span><span class="identifier">prog</span><span>.</span><span class="identifier">foldMap</span><span>[</span><span class="type-name">FromString</span><span>](</span><span class="identifier">compiler</span><span>)
</span><span class="comment">// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$14542/0x00007f397f6e18c8@11120a47
</span><span class="comment">// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$14453/0x00007f1ed06e7958@6077f7ee
</span><span class="identifier">validator</span><span>(</span><span class="string-literal">&quot;1234&quot;</span><span>)
</span><span class="comment">// res0: Boolean = false
</span><span class="identifier">validator</span><span>(</span><span class="string-literal">&quot;12345&quot;</span><span>)
Expand Down
4 changes: 2 additions & 2 deletions datatypes/freemonad.html
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ <h2 id="freet" class="section"><a class="anchor-link left" href="#freet"><i clas
</span><span class="keyword">import</span><span> </span><span class="type-name">TeletypeOps</span><span>.</span><span class="identifier">_</span><span>

</span><span class="keyword">val</span><span> </span><span class="identifier">state</span><span> = </span><span class="identifier">program</span><span>.</span><span class="identifier">foldMap</span><span>(</span><span class="identifier">interpreter</span><span>)
</span><span class="comment">// state: TeletypeState[Unit] = cats.data.IndexedStateT@5f0dc21c
</span><span class="comment">// state: TeletypeState[Unit] = cats.data.IndexedStateT@78de5324
</span><span class="keyword">val</span><span> </span><span class="identifier">initialState</span><span> = </span><span class="type-name">Nil</span><span>
</span><span class="comment">// initialState: Nil.type = List()
</span><span class="keyword">val</span><span> (</span><span class="identifier">stored</span><span>, </span><span class="identifier">_</span><span>) = </span><span class="identifier">state</span><span>.</span><span class="identifier">run</span><span>(</span><span class="identifier">initialState</span><span>).</span><span class="identifier">value</span><span>
Expand Down Expand Up @@ -789,7 +789,7 @@ <h2 id="freet" class="section"><a class="anchor-link left" href="#freet"><i clas
// value = Success(value = Some(value = Left(value = Action(value = 7))))
// )
// ),
// f0 = scala.Function1$$Lambda$14381/0x00007f397f648f60@5b879b36
// f0 = scala.Function1$$Lambda$14292/0x00007f1ed0606d40@5e10e809
// )
</span><span class="keyword">val</span><span> </span><span class="identifier">evaluated</span><span> = </span><span class="identifier">hoisted</span><span>.</span><span class="identifier">foldMap</span><span>(</span><span class="identifier">tryInterpreter</span><span>)
</span><span class="comment">// evaluated: OptTry[Int] = OptionT(value = Success(value = Some(value = 12)))
Expand Down
4 changes: 2 additions & 2 deletions datatypes/state.html
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ <h2 id="changing-states" class="section"><a class="anchor-link left" href="#chan
</span><span class="identifier">_</span><span> &lt;- </span><span class="identifier">close</span><span>
</span><span class="identifier">_</span><span> &lt;- </span><span class="identifier">open</span><span>
} </span><span class="keyword">yield</span><span> ()
</span><span class="comment">// valid: IndexedStateT[Eval, Closed.type, Open.type, Unit] = cats.data.IndexedStateT@5264eff5</span></code></pre>
</span><span class="comment">// valid: IndexedStateT[Eval, Closed.type, Open.type, Unit] = cats.data.IndexedStateT@34c83bda</span></code></pre>
<p>Note that the inferred type of <code>valid</code> correctly models that this computation can be executed only with an initial <code>Closed</code> state.</p>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="identifier">valid</span><span>.</span><span class="identifier">run</span><span>(</span><span class="type-name">Open</span><span>)
</span><span class="comment">// error: type mismatch;
Expand All @@ -483,7 +483,7 @@ <h2 id="changing-states" class="section"><a class="anchor-link left" href="#chan
// valid.run(Open)
// ^^^^</span></code></pre>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="identifier">valid</span><span>.</span><span class="identifier">run</span><span>(</span><span class="type-name">Closed</span><span>)
</span><span class="comment">// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@2542e677</span></code></pre>
</span><span class="comment">// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@5c09867f</span></code></pre>


<hr class="footer-rule"/>
Expand Down
4 changes: 2 additions & 2 deletions typeclasses/bifoldable.html
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ <h2 id="tuple-as-bifoldable" class="section"><a class="anchor-link left" href="#
(</span><span class="identifier">s</span><span>, </span><span class="identifier">acc</span><span>) =&gt; </span><span class="identifier">acc</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">_</span><span> |+| </span><span class="identifier">s</span><span>),
(</span><span class="identifier">s</span><span>, </span><span class="identifier">acc</span><span>) =&gt; </span><span class="identifier">acc</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">_</span><span> |+| </span><span class="identifier">s</span><span>)
)
</span><span class="comment">// right: Eval[String] = cats.Eval$$anon$1@18c74de3
</span><span class="comment">// right: Eval[String] = cats.Eval$$anon$1@4cf4c56e
</span><span>
</span><span class="identifier">left</span><span> === </span><span class="identifier">expected</span><span>
</span><span class="comment">// res2: Boolean = true
Expand All @@ -354,7 +354,7 @@ <h2 id="tuple-as-bifoldable" class="section"><a class="anchor-link left" href="#
(</span><span class="identifier">s</span><span>, </span><span class="identifier">acc</span><span>) =&gt; </span><span class="identifier">acc</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">_</span><span> |+| </span><span class="identifier">s</span><span>),
(</span><span class="identifier">s</span><span>, </span><span class="identifier">acc</span><span>) =&gt; </span><span class="identifier">acc</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">_</span><span> |+| </span><span class="identifier">s</span><span>)
)
</span><span class="comment">// reversedRight: Eval[String] = cats.Eval$$anon$1@fdaceec
</span><span class="comment">// reversedRight: Eval[String] = cats.Eval$$anon$1@68a657c1
</span><span>
</span><span class="identifier">reversedRight</span><span>.</span><span class="identifier">value</span><span> === </span><span class="identifier">expected</span><span>
</span><span class="comment">// res4: Boolean = false</span></code></pre>
Expand Down
2 changes: 1 addition & 1 deletion typeclasses/bifunctor.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ <h2 id="either-as-a-bifunctor" class="section"><a class="anchor-link left" href=
</span><span class="identifier">error</span><span> =&gt; </span><span class="type-name">DomainError</span><span>(</span><span class="identifier">error</span><span>.</span><span class="identifier">getMessage</span><span>),
</span><span class="identifier">dateTime</span><span> =&gt; </span><span class="identifier">dateTime</span><span>.</span><span class="identifier">toEpochSecond</span><span>
)
</span><span class="comment">// res0: Either[DomainError, Long] = Right(value = 1725173999L)</span></code></pre>
</span><span class="comment">// res0: Either[DomainError, Long] = Right(value = 1725412098L)</span></code></pre>
<p><code>Bifunctor</code> also defines a convenience function called <code>leftMap</code>, which is defined as follows:</p>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="keyword">def</span><span> </span><span class="declaration-name">leftMap</span><span>[</span><span class="type-name">A</span><span>, </span><span class="type-name">B</span><span>, </span><span class="type-name">C</span><span>](</span><span class="identifier">fab</span><span>: </span><span class="type-name">F</span><span>[</span><span class="type-name">A</span><span>, </span><span class="type-name">B</span><span>])(</span><span class="identifier">f</span><span>: </span><span class="type-name">A</span><span> =&gt; </span><span class="type-name">C</span><span>): </span><span class="type-name">F</span><span>[</span><span class="type-name">C</span><span>, </span><span class="type-name">B</span><span>] = </span><span class="identifier">bimap</span><span>(</span><span class="identifier">fab</span><span>)(</span><span class="identifier">f</span><span>, </span><span class="identifier">identity</span><span>)</span></code></pre>
<p>There is no <code>rightMap</code> however - use <code>map</code> instead. The reasoning behind this is that in Cats, the instances of
Expand Down
2 changes: 1 addition & 1 deletion typeclasses/bimonad.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ <h3 id="nonemptylist-as-a-bimonad" class="section"><a class="anchor-link left" h
</span><span> </span><span class="keyword">override</span><span> </span><span class="keyword">def</span><span> </span><span class="declaration-name">tailRecM</span><span>[</span><span class="type-name">A</span><span>, </span><span class="type-name">B</span><span>](</span><span class="identifier">a</span><span>: </span><span class="type-name">A</span><span>)(</span><span class="identifier">fn</span><span>: </span><span class="type-name">A</span><span> =&gt; </span><span class="type-name">NonEmptyList</span><span>[</span><span class="type-name">Either</span><span>[</span><span class="type-name">A</span><span>, </span><span class="type-name">B</span><span>]]): </span><span class="type-name">NonEmptyList</span><span>[</span><span class="type-name">B</span><span>] =
???
}
</span><span class="comment">// nelBimonad: Bimonad[NonEmptyList] = repl.MdocSession$MdocApp$$anon$1@259adddf</span></code></pre>
</span><span class="comment">// nelBimonad: Bimonad[NonEmptyList] = repl.MdocSession$MdocApp$$anon$1@4759ec16</span></code></pre>
<p>Note the equivalence:</p>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="identifier">nelBimonad</span><span>.</span><span class="identifier">pure</span><span>(</span><span class="boolean-literal">true</span><span>).</span><span class="identifier">extract</span><span> === </span><span class="type-name">NonEmptyList</span><span>.</span><span class="identifier">one</span><span>(</span><span class="boolean-literal">true</span><span>).</span><span class="identifier">head</span><span>
</span><span class="comment">// res0: Boolean = true</span></code></pre>
Expand Down
Loading

0 comments on commit e3cc105

Please sign in to comment.