Run1 scala functional programming for data processing
Functional programming patterns in Scala for data transformation, collection processing, and batch operations suitable for distributed systems.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill run1_scala-functional-programming-for-data-processingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.5 KB, 320 tokens by cl100k_base, as published. Nobody here has run it
Functional Data Transformation
Map, Filter, FlatMap
tokens.map(token => token.copy(value = token.value.toUpperCase))
tokens.filter(token => token.tokenType == StringToken)
tokens.flatMap(token => // transform to multiple elements
For-Comprehensions
- Alternative to nested map/flatMap: more readable syntax
for {
token <- tokens
if token.value.nonEmpty
} yield token.copy(metadata = token.metadata + ("processed" -> "true"))
Batch Processing Patterns
Processing Lists of Inputs
def tokenizeBatch(inputs: List[String]): List[List[Token]] = {
inputs.map(tokenize)
}
Handling Options
Option(value).map(_.toInt).getOrElse(0)
Try { riskyOperation }.toOption
value match {
case Some(x) => // handle
case None => // handle
}
Immutability and Copy Patterns
Using Case Class copy
token.copy(metadata = token.metadata + ("key" -> "value"))
Avoiding Mutable Collections
- Use immutable
List,Map,Setfrom Scala stdlib - Chain operations rather than accumulating state
Higher-Order Functions
Functions as Parameters
def process(tokens: List[Token], transform: Token => Token): List[Token] = {
tokens.map(transform)
}
Composition
val pipeline = tokenize _ andThen filterEmpty andThen enrichMetadata
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.