Skip to content

Caleb-o/store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

store

Package Version Hex Docs Erlang-compatible JavaScript-compatible

An immutable store structure, with the ability to add subscribers. Subscribe with callbacks that will be called when a set or update is called on a store. Checkout the mutable version, mut_cell with a mutable store that changes the value in place.

Install

gleam add store@1
import store
import gleam/int
import gleam/io

pub fn main() {
  let cell = store.make(10)

  let #(cell, unsub) =
    cell
    |> store.subscribe(fn(value) {
      { "value: " <> value |> int.to_string } |> io.println
    })

  let cell = cell |> store.set(20)

  let cell = unsub(cell)

  let cell = cell |> store.set(30)

  cell
  |> store.get
  |> int.to_string
  |> io.println
}

Further documentation can be found at https://hexdocs.pm/store.

About

An immutable store with subscriptions in Gleam

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages