Current section

Files

Jump to
memory README.md
Raw

README.md

# memory
为函数提供记忆,不支持递归缓存。
[![Package Version](https://img.shields.io/hexpm/v/memory)](https://hex.pm/packages/memory)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://memory.hexdocs.pm/)
```sh
gleam add memory
```
```gleam
import memory
pub fn factorial(i: Int) -> Int {
factorial_loop(i, i)
}
fn factorial_loop(i: Int, acc: Int) -> Int {
case i {
0 | 1 -> acc
_ -> factorial_loop(i - 1, acc * { i - 1 })
}
}
pub fn main() {
let assert Ok(#(factorial, cache)) = memory.new(factorial, 10)
}
```
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
```