Skip to content

aosasona/purse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

purse

Package Version Hex Docs

import gleam/dynamic
import gleam/erlang/atom
import gleam/io
import purse
import purse/named

pub type Test {
  Test
}

pub type Data {
  Data(key: String, value: String, point: Int)
}

pub fn main() {
  let decoder =
    dynamic.decode3(
      Data,
      dynamic.element(at: 1, of: dynamic.string),
      dynamic.element(at: 2, of: dynamic.string),
      dynamic.element(at: 3, of: dynamic.int),
    )

  let table_name = atom.create_from_string("test")

  let assert Ok(t) =
    named.new(
      name: table_name,
      visibility: named.Public,
      table_type: named.Bag,
      accepts: decoder,
    )

  let _ = insert(t, string("foo"), Data("bar", "baz", 1))
  let _ = insert(t, string("foo"), Data("ayy", "bee", 2))
  let _ = insert(t, string("foo"), Data("cee", "dee", 3))

  lookup(t, string("foo"))
  |> io.debug
}

Running this produces the following output:

Ok([Data("cee", "dee", 3), Data("ayy", "bee", 2), Data("bar", "baz", 1)])

Quick start

gleam run   # Run the project
gleam test  # Run the tests
gleam shell # Run an Erlang shell

Installation

If available on Hex this package can be added to your Gleam project:

gleam add purse

and its documentation can be found at https://hexdocs.pm/purse.

About

[WIP] Use Erlang ETS in Gleam

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published