Run2 scala option handling
Handling absence and nullability in Scala using Option, with patterns for translating Python None handling.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill run2_scala-option-handlingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.0 KB, 230 tokens by cl100k_base, as published. Nobody here has run it
Option Handling in Scala
Python None -> Scala Option
x: str | None->x: Option[String]if x is None->x match { case None => ... case Some(v) => ... }- Or use
.map,.flatMap,.getOrElse,.fold
Processing Pipelines with Option
Instead of mutable var + early returns:
// BAD (Python-like)
var w = word
if (condition) w = transform(w)
if (w.length < min) return None
// GOOD (functional Scala)
Some(word)
.map(w => if (condition) transform(w) else w)
.filter(_.length >= min)
.map(w => maxLen.fold(w)(m => w.take(m)))
.filter(_.nonEmpty)
Option with Collections
list.flatMap(f)wherefreturnsOptionnaturally filters NonecollectFirstfor finding first matching elementiterator.map(...).collectFirst { case Some(x) => x }for lazy first-match
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.