Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chadtech/random-pcg-pipeline
This is a package that makes getting random values a little bit easier in Elm.
https://github.com/chadtech/random-pcg-pipeline
elm random
Last synced: 1 day ago
JSON representation
This is a package that makes getting random values a little bit easier in Elm.
- Host: GitHub
- URL: https://github.com/chadtech/random-pcg-pipeline
- Owner: Chadtech
- Created: 2018-02-03T20:27:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-03T20:32:07.000Z (almost 7 years ago)
- Last Synced: 2024-11-06T04:40:57.811Z (about 2 months ago)
- Topics: elm, random
- Language: Elm
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Random Pcg Pipeline
This is a package that makes getting random values a little bit easier in Elm. Its just like the package `Chadtech/random-pipeline`, except its adapted to use `mgold/elm-random-pcg` instead of the core random package.
Heres a side by side comparison between `Random` and `Random.Pipeline`
```elm
-- Random
modelGenerator : Generator Model
modelGenerator =
Random.map4 Model
positionGenerator
enemiesGenerator
uuidGenerator
nameGeneratorinit : Seed -> ( Model, Seed )
init =
Random.step modelGenerator-- Random.Pcg.Pipeline
import Random.Pcg.Pipeline exposing (from, with)init : Seed -> ( Model, Seed )
init seed =
Model
|> from seed
|> with positionGenerator
|> with enemiesGenerator
|> with uuidGenerator
|> with nameGenerator
```A little bit cleaner right? And what if we wanted to keep the seed in our `Model` too? Just use `Random.Pipeline.finish`
```elm
import Random.Pcg.Pipeline exposing (from, with, finish)init : Seed -> Model
init seed =
Model
|> from seed
|> with positionGenerator
|> with enemiesGenerator
|> with uuidGenerator
|> with nameGenerator
|> finishtype alias Model =
{ pos : Position
, enemies : List Enemy
, uuid : Uuid
, name : String
, seed : Seed
}
```It also has `always` that can hardcode values into your random generation.
```elm
import Random.Pcg.Pipeline exposing (from, with, finish, always)update : Msg -> Model -> Model
update msg model =
case msg of
Restart ->
Model
|> from model.seed
|> with positionGenerator
|> with enemiesGenerator
|> always model.uuid
|> always model.name
|> finish
```