Skip to content

mscharley/gleam-worm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

worm 🪱

Package Version Hex Docs

gleam add worm
import gleam/regex
import worm

type RegexCache {
  RegexCache(greeting: regex.Regex, name: regex.Regex)
}

fn regexes() -> RegexCache {
  use <- worm.persist()
  let assert Ok(greeting) = regex.from_string("^\\w+")
  let assert Ok(name) = regex.from_string("\\w+$")
  RegexCache(greeting, name)
}

pub fn main() {
  let RegexCache(greeting: initial, ..) = regexes()

  "Hello, Gleam!"
  |> regex.scan(with: initial) // [regex.Match("Hello", [])]

  Nil
}

While this library was initial concieved of as a cache for regex compilation, it can be used for any deterministic calculation which you only want to run once and reuse many times.

Please read the documentation before using this library as it is not the best solution for many situations. API documentation can be found at https://hexdocs.pm/worm/worm.html.

About

A library for caching deterministic calculations in Gleam

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors