agentsclimarketplace

Scala higher kinded types

Skill cxcscmu/SkillLearnBench/skills/b4-skill-creator-gemini-3.1-pro-preview/python-scala-translation/scala-higher-kinded-types

Translating Python simulated Functors and Monads to Scala Higher-Kinded Types. Use this skill whenever implementing functional programming concepts like Functor, Monad, Applicative in Scala.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill scala-higher-kinded-types

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

1.2 KB, 271 tokens by cl100k_base, as published. Nobody here has run it

Scala Higher-Kinded Types

In Python, HKTs are simulated because Python's type system lacks them. In Scala, you can express them directly, but sometimes a simple generic class is sufficient depending on the spec.

Functor Example

A TokenFunctor[T] can be a generic class with map operations:

class TokenFunctor[T](val value: T) {
  def map[U](f: T => U): TokenFunctor[U] = new TokenFunctor(f(value))
  def flatMap[U](f: T => TokenFunctor[U]): TokenFunctor[U] = f(value)
  def getOrElse[U >: T](default: => U): U = if (value != null) value else default
  def get: T = value
}

Applicative/Monad Apply

For an Applicative's ap method (in a TokenMonad subclass):

class TokenMonad[T](value: T) extends TokenFunctor[T](value) {
  def ap[U](funcWrapped: TokenMonad[T => U]): TokenMonad[U] = 
    new TokenMonad(funcWrapped.value(this.value))
}
object TokenMonad {
  def pure[T](value: T): TokenMonad[T] = new TokenMonad(value)
}

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.