Simple algebraic dice notation parser for Gleam
3

Configure Feed

Select the types of activity you want to include in your feed.

Add code docs

Naomi Roberts (May 9, 2025, 4:31 PM +0100) 4e040dd5 b6395460

+10
+10
src/diced.gleam
··· 37 37 ] 38 38 39 39 pub type Dice { 40 + /// A "normal" dice roll with an amount, value and a list of modifiers to apply 40 41 Basic(amount: Int, value: Int, modifiers: List(Modifier)) 42 + /// A fate dice roll with an amount, and a list of modifiers to apply. Fate dice are dice with 3 results, all with an 43 + /// equal number of faces. [Learn more](https://en.wikipedia.org/wiki/Fudge_%28role-playing_game_system%29) 41 44 Fate(amount: Int, modifiers: List(Modifier)) 45 + /// A basic number and some modifiers that could be applied. 42 46 Number(value: Int, modifiers: List(Modifier)) 43 47 } 44 48 ··· 49 53 InvalidModifier 50 54 } 51 55 56 + /// Convert a string containing algebraic dice notation into a type describing how the dice should behave when rolled. 57 + /// 58 + /// ```gleam 59 + /// diced.parse("2d20kh") 60 + /// // Ok(diced.Basic(2, 20, [KeepHighest(1)])) 61 + /// ``` 52 62 pub fn parse(string string: String) -> Result(Dice, DiceError) { 53 63 let dice_splitter = splitter.new(["d", "dF"]) 54 64 case splitter.split(dice_splitter, string) {