Run3 scala fluent builder pattern
Implement a fluent Builder pattern in Scala to provide a clean API for object configuration and instantiation.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill run3_scala-fluent-builder-patternAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.2 KB, 232 tokens by cl100k_base, as published. Nobody here has run it
Fluent Builder Implementation
The TokenizerBuilder should provide a functional and fluent interface.
- State Management: The builder can maintain an internal state using a
private var(encapsulated) or by returning a new version of the builder case class with updated fields. - Method Chaining: Ensure methods return
this.type(for mutable builders) or a new instance of the builder (for immutable builders). This allows the user to chain calls like.withType(...).withModel(...). - The Build Method: Provide a
build()method that validates the current state and instantiates the appropriateBaseTokenizerimplementation.
Pattern Structure
class TokenizerBuilder {
private var tokenizerType: String = _
def setType(t: String): this.type = {
this.tokenizerType = t
this
}
def build(): BaseTokenizer = {
// Logic to return specific implementation based on tokenizerType
}
}
This pattern provides a clear, type-safe API for constructing complex objects while hiding the instantiation logic of the specific tokenizer subclasses.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.