Skip to content

gleam-lang/yielder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yielder

Unfold values on-demand from a function.

Package Version Hex Docs

You may want to use this library when you have a function that can generate a sequence of values but the sequence is too large to fit into memory, or it would be wasteful to do so. You could instead create a Yielder for it and only have the section you are working on in memory, and halt evaluation when you have consumed as much of the sequence as you need for your program.

gleam add gleam_yielder@1
import gleam/yielder

pub fn main() {
  yielder.unfold(2, fn(acc) { yielder.Next(acc, acc * 2) })
  |> yielder.take(5)
  |> yielder.to_list
  // -> [2, 4, 8, 16, 32]
}

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

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages