Skip to content

Instantly share code, notes, and snippets.

View ahoy-jon's full-sized avatar
🐋
Thinking!

Jonathan Winandy ahoy-jon

🐋
Thinking!
  • Paris/France
View GitHub Profile
@ahoy-jon
ahoy-jon / project.scala
Created September 23, 2025 23:34
Direct Style vs Monadic Style Example
//> using scala 3.7.3
//> using dep in.rcard.raise4s::core:0.5.0
//> using dep io.getkyo::kyo-core::1.0-RC1
//> using dep io.getkyo::kyo-direct::1.0-RC1
//> using dep io.getkyo::kyo-combinators::1.0-RC1
import in.rcard.raise4s.*
import kyo.*
@ahoy-jon
ahoy-jon / Kyo-Lift.md
Last active September 7, 2025 10:40
Lifting Values in Kyo

Lifting Values in Kyo

In the Kyo framework, a common and fundamental operation is the transformation of a simple value A into an effectful value A < S. This process, known as "lifting," allows a plain value to be seamlessly integrated into Kyo's effect system. While this can be done explicitly, it is most often handled implicitly by the Kyo compiler, which makes for cleaner and more concise code.

Explicit Lifting

The most direct way to lift a value is by using the Kyo.lift function. This function takes a value and wraps it in a Kyo effect type.

val v1: Int &lt; Any = Kyo.lift(1)

2025-08-20 Original post.

2025-08-24 I'd like to refine the terminology used. The pattern demonstrated here is most accurately described as "polymorphism over effects, (using Higher-Kinded Types)".

It's important to distinguish this from other related concepts. Although it bears a strong resemblance to the Tagless Final pattern, this approach is distinct, and as a tight (not vendor free) integration with Kyo. Furthermore, please note that it is not "Effect Polymorphism," which is an alternate and less precise phrasing.

Thanks a lot to all of you for the valuable feedback!


//> using scala "3.7.1-RC2"
//> using dep io.getkyo::kyo-core:0.19.0+40-6e6cea21+20250603-1734-SNAPSHOT
//> using dep io.getkyo::kyo-prelude:0.19.0+40-6e6cea21+20250603-1734-SNAPSHOT
//> using dep io.getkyo::kyo-direct:0.19.0+40-6e6cea21+20250603-1734-SNAPSHOT
//> using dep org.scalatest::scalatest:3.2.19
//> using option -Wvalue-discard
import scala.annotation.{ nowarn, tailrec }
import kyo.*
val a = 1
def doSomething(): Unit = {
println("do")
println("something")
}
//> using scala 3.4.2
//> using dep "io.swagger.core.v3:swagger-annotations-jakarta:2.2.22"
//> using dep "com.softwaremill.sttp.tapir:tapir-core_3:1.11.0"
import io.swagger.v3.oas.annotations.media.{Schema => OpenApiSchema}
import sttp.tapir.*
import sttp.tapir.generic.auto.*
#awk '
function chunk_mod(s) {
len = 6 # 6 digits in case of 32-bit awk version
result = 0
while (length(s) > 0) {
chunk = substr(s, 1, len)
s = substr(s, len + 1)
result = (result * (10 ^ length(chunk)) + chunk) % 97
}
return result
@ahoy-jon
ahoy-jon / Main.scala
Created April 15, 2023 08:25
Read - write Kafka - Sans protections
import org.apache.kafka.clients.consumer.{ConsumerConfig, KafkaConsumer}
import org.apache.kafka.common.serialization.{StringDeserializer, StringSerializer}
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig
import org.apache.avro.generic.GenericRecord
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig, ProducerRecord}
import java.util.Properties
import scala.jdk.CollectionConverters._

Keybase proof

I hereby claim:

  • I am ahoy-jon on github.
  • I am ahoy_jon (https://keybase.io/ahoy_jon) on keybase.
  • I have a public key whose fingerprint is 2D1F 3333 68BF 23E6 0B5F 97EC AA13 2117 84F5 5FCC

To claim this, I am signing this object:

sealed abstract class Cont[Result, +H] {
final def map[H2](fn: H => H2): Cont[Result, H2] = flatMap(h => Cont.pure(fn(h)))
final def flatMap[H2](fn: H => Cont[Result, H2]): Cont[Result, H2] = Cont.FlatMapped(this, fn)
def apply(fn: H => Result): Result
}
object Cont {
case class Wrap[Result, H](f: (H => Result) => Result) extends Cont[Result, H] {