https://github.com/sgraf812/elm-stateful
Library for conveniently working with stateful computations
https://github.com/sgraf812/elm-stateful
Last synced: 4 months ago
JSON representation
Library for conveniently working with stateful computations
- Host: GitHub
- URL: https://github.com/sgraf812/elm-stateful
- Owner: sgraf812
- License: mit
- Created: 2015-06-22T17:18:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-22T19:48:37.000Z (about 10 years ago)
- Last Synced: 2025-01-19T15:52:15.020Z (6 months ago)
- Language: Elm
- Size: 121 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stateful [](https://travis-ci.org/sgraf812/elm-stateful)
A small library with primitives for working with stateful computations. This is neat when trying to imitate mutable variables, for example random number seeds or just generating automatically incrementing ids like so:
```
nextId : Stateful Int Int
nextId =
Stateful.get `Stateful.andThen` \id ->
Stateful.put (id + 1) `Stateful.andThen` \_ ->
Stateful.return idthreeIds : List Int
threeIds =
fst <| Stateful.run
(Stateful.sequence
[ nextId
, nextId
, nextId
])
3
-- threeIds = [3, 4, 5]
```The advantage here is that we don't need to manually thread a counter variable in a let binding.