Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sgraf812/elm-stateful
Library for conveniently working with stateful computations
https://github.com/sgraf812/elm-stateful
Last synced: 5 days 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 (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-22T19:48:37.000Z (over 9 years ago)
- Last Synced: 2024-11-18T15:13:17.292Z (2 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 [![Build Status](https://travis-ci.org/sgraf812/elm-stateful.svg)](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.