gs - A lightweight Gleam library that introduces the Stream type for handling lazy value sequences. The library offers comprehensive functionality for creating, transforming, and processing streams, enabling efficient manipulation of sequential data.
A Stream consists of a Source element that generates data, followed by zero or more Pipe elements that transform the data, and concludes with a Sink element that consumes the data to produce a result.
The Source is a lazy data structure that represents a sequence of values. It enables on-demand evaluation, making it highly efficient for processing large or infinite data sets. The library includes several built-in sources, such as from_list, from_range, and from_tick, which all follow the naming convention of starting with from_.
The Pipe elements are functions that transform the data in the stream. They can be used to map, or filter the data, among other operations like executing side effects. The library provides a variety of built-in pipe functions, such as map, filter, and take, which can be combined to create complex data processing pipelines.
The Sink is a function that processes data from a stream to generate a result. It can collect data into a list, subject or fold in a single value. Additionally, a Sink can terminate an infinite stream by consuming elements until a specific termination condition is met, such as to_nil_error_terminated.
Add gs to your Gleam project:
gleam add gsCheck out the /examples directory for sample implementations.
Further documentation can be found at https://hexdocs.pm/gs.
Import gs/text for convenience helpers when working with textual data:
utf8_decode/utf8_encodeconvert betweenStream(BitArray)andStream(String).utf8_decode_dropremoves invalid UTF-8 sequences while decoding.linesturns a chunked stream of strings into a stream of complete lines.splitsupports custom delimiters that may span chunk boundaries.
import gs
import gs/text
gs.from_list(["foo\nbar", "\nbaz"])
|> text.lines
|> gs.to_list
// -> ["foo", "bar", "baz"]This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
gleam run # Run the project
gleam test # Run the tests