Rumpel is a Scala 3 library for generating unique, human-readable names. Inspired by the mythological figure Rumpelstiltskin, who wove straw into gold, this library weaves random words into memorable names. It’s a Scala port of the popular unique-names-generator.
- Fully compatible with Scala 3.
- Generate unique names using customizable dictionaries and configurations.
- Control separators, styles, and length of the generated names.
- Lightweight, efficient, and idiomatic to Scala.
- Open source and maintained by the io.funktional organization.
Add the following dependency to your build.sbt
:
libraryDependencies += "io.funktional" %% "rumpel" % "<version>"
If you are compiling for non-JVM targets, you can use the cross-versioned dependency:
libraryDependencies += "io.funktional" %%% "rumpel" % "<version>"
Here’s an example of how to use Rumpel:
import io.funktional.rumpel.*
import io.funktional.rumpel.dictionaries.Adjectives
import io.funktional.rumpel.dictionaries.Animals
import io.funktional.rumpel.dictionaries.Colors
object Example extends App:
val config = RumpelConfig(
dictionaries = List(Adjectives, Colors, Animals),
separator = "-",
length = 3
)
val rumpel = new Rumpel(config)
println(rumpel.generate()) // Example: "brave-red-fox"
It is possible to use a custom random number generator by providing an instance of io.funktional.rumpel.Random
:
object MyRandom extends io.funktional.rumpel.Random:
def nextInt(n: Int): (Random, Int) =
??? // Implement your own logic here
def shuffle[T](elements: List[T]): (Random, List[T]) =
??? // Implement your own logic here
def pick[T](list: List[T], n: Int): (Random, List[T]) =
??? // Implement your own logic here
object Example extends App:
val config = RumpelConfig(
dictionaries = List(Adjectives, Colors, Animals),
separator = "-",
length = 3
)
val rumpel = new Rumpel(config, MyRandom)
println(rumpel.generate()) // Example: "brave-red-fox"
You can customize Rumpel by providing a RumpelConfig
:
- dictionaries: A list of word dictionaries to draw from (e.g., adjectives, animals, colors).
- separator: A string used to separate words (default: "-").
- length: The number of words in the generated name (default: 3).
The library includes built-in dictionaries for:
- Adjectives: e.g., "brave", "calm", "diligent".
- Colors: e.g., "red", "blue", "green".
- Animals: e.g., "fox", "bear", "eagle".
You can also add your own custom dictionaries.
- Expand built-in dictionaries.
- Introduce advanced customization features.
- Provide integration examples with popular Scala frameworks.
Contributions are welcome! Here’s how to get started:
- Fork the repository.
- Create a new branch: git checkout -b feature-name.
- Make your changes and commit: git commit -m "Add feature".
- Push the branch: git push origin feature-name.
- Open a pull request.
To build Rumpel locally, clone the repository and use sbt:
git clone https://github.com/io.funktional/rumpel.git
cd rumpel
sbt compile
Run tests with:
sbt test
This project is licensed under the Eclipse Public License - v 2.0.
Rumpel is inspired by the unique-names-generator library and brings its functionality into the Scala ecosystem.