agentsclimarketplace

Run2 scala immutable builder

Skill cxcscmu/SkillLearnBench/skills/b2-self-feedback-claude-opus-4-6/python-scala-translation/run2_scala-immutable-builder

Implementing the builder pattern in Scala using immutable case classes or private constructors with copy.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill run2_scala-immutable-builder

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

SKILL.md

1.1 KB, 216 tokens by cl100k_base, as published. Nobody here has run it

Immutable Builder Pattern in Scala

Using Private Constructor + Companion Object

class Builder[T] private (
  normalizers: Vector[String => String],
  validators: Vector[T => Boolean],
  metadata: Map[String, Any]
) {
  def withNormalizer(f: String => String): Builder[T] =
    new Builder(normalizers :+ f, validators, metadata)

  def withMetadata(entries: (String, Any)*): Builder[T] =
    new Builder(normalizers, validators, metadata ++ entries.toMap)

  def build(): T => Result = { value =>
    validators.foreach(v => if (!v(value)) throw new IllegalArgumentException(...))
    val str = normalizers.foldLeft(value.toString)((s, f) => f(s))
    Result(str, metadata)
  }
}

object Builder {
  def apply[T](): Builder[T] = new Builder(Vector.empty, Vector.empty, Map.empty)
}

Key: immutable collections (Vector, Map) ensure thread safety. Each with* method returns a new instance.

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.