These are code examples for the “Functional event sourcing example in Kotlin” article:
All gists:
-
Functional event sourcing example in Kotlin
| import Mathlib | |
| inductive Operation | add | sub | mul | div | |
| deriving DecidableEq | |
| def Operation.parse (input : String) : Option Operation := | |
| match input with | |
| | "+" => .some .add | "-" => .some .sub | |
| | "*" => .some .mul | "/" => .some .div | |
| | _ => .none |
| //> using scala 3.7 | |
| //> using dep org.http4s::http4s-ember-server:0.23.30 | |
| //> using dep org.http4s::http4s-dsl:0.23.30 | |
| //> using dep org.http4s::http4s-scalatags::0.25.2 | |
| //> using option -Wunused:all | |
| import scalatags.Text.all.* | |
| import cats.effect.* | |
| import fs2.Stream | |
| import org.http4s.* | |
| import org.http4s.dsl.io.* |
| object Derive: | |
| import scala.quoted.* | |
| inline def derive[Contents, Mask]: NotIn[Contents, Mask] = | |
| ${ deriveImpl[Contents, Mask] } | |
| private def deriveImpl[Contents: Type, Mask: Type](using q: Quotes): Expr[NotIn[Contents, Mask]] = { | |
| import quotes.reflect.* | |
| if (inMask[Contents, Mask]) { | |
| report.errorAndAbort(s"Type ${Type.show[Contents]} is in Mask: ${Type.show[Mask]}") | |
| } else { |
These are code examples for the “Functional event sourcing example in Kotlin” article:
All gists:
Functional event sourcing example in Kotlin
| #!/usr/bin/env bash | |
| # Tested with jq 1.6 & fzf 0.42.0 | |
| # Inspired by https://github.com/reegnz/jq-zsh-plugin | |
| # Call with `jazz <big_file_with_many_paths>.json` or `<command producing a valid json> | jazz` | |
| # End command with `... | pbcopy` or `... > output.json` to save selection | |
| input=$1 | |
| TMP_DIR=$(mktemp -d /tmp/jazz_XXX) | |
| chmod 700 "$TMP_DIR" |
| //> using lib "com.softwaremill.sttp.openai::core:0.0.6" | |
| object ai: | |
| import scala.quoted.* | |
| import sttp.openai.OpenAISyncClient | |
| import sttp.openai.requests.completions.chat.* | |
| import sttp.openai.requests.completions.chat.ChatRequestBody.ChatBody | |
| import sttp.openai.requests.completions.chat.ChatRequestBody.ChatCompletionModel | |
| opaque type GPT[A <: String] <: String = String |
| [keys.normal] | |
| C-f = [":new", ":insert-output lf-pick", ":theme default", "select_all", "split_selection_on_newline", "goto_file", "goto_last_modified_file", ":buffer-close!", ":theme tokyonight_storm"] |
Проверять метод на скрытость, можете тут: vk.com/dev/МЕТОД
Yoneda (and its duel Coyoneda) is well known in the Category Theory field and has been ported over to functional languages such as Haskell. Each have their uses - sometimes in similar scenarios, also in very different ways.
This will be a newbie's explanation of the concept, using Haskell to illustrate, without any Category Theory.
From what I've read, the Yonedas are not 'daily-drivers' (not used everyday), but rather can be pulled out when the time is right.
Uses: Both Yoneda's can be used to help speed up a program where there are many fmap with long lists or big trees involved. Coyoneda can be used if you want to create an 'interface' and build up calculations, then pass those calculations to an 'executor' to run them.
| {-# language OverloadedLists #-} | |
| {-# OPTIONS_GHC -Wall #-} | |
| module Overlays where | |
| import Prelude hiding ((.)) | |
| import GHC.Stack | |
| import Debug.Trace |