Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thatscalaguy/gs
https://github.com/thatscalaguy/gs
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/thatscalaguy/gs
- Owner: ThatScalaGuy
- Created: 2024-12-21T19:54:23.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-12-21T20:08:17.000Z (about 1 month ago)
- Last Synced: 2024-12-21T20:19:39.059Z (about 1 month ago)
- Language: Gleam
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gs - Gleam Streams
[![Package Version](https://img.shields.io/hexpm/v/gs)](https://hex.pm/packages/gs)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gs/)`gs` is a lightweight Gleam library for working with streams of data. It provides a variety of functions for creating, transforming, and consuming streams, making it easy to perform local transformations on lists.
## Installation
Add `gs` to your Gleam project:
```sh
gleam add gs
```## Usage
Here are some examples of how to use `gs`:
### Creating Streams
```gleam
import gs.{empty, pure, from_list, from_option, from_result}let empty_stream = empty()
let single_value_stream = pure(42)
let list_stream = [1, 2, 3] |> from_list
let option_stream = Some(42) |> from_option
let result_stream = Ok(42) |> from_result
```### Transforming Streams
```gleam
import gs.{repeat, repeat_eval, map, flat_map, filter, take, concat}let repeated_stream = 42 |> repeat
let evaluated_stream = fn() { 42 } |> repeat_eval
let mapped_stream = repeated_stream |> map(fn(x) { x + 1 })
let flat_mapped_stream = repeated_stream |> flat_map(fn(x) { pure(x + 1) })
let filtered_stream = repeated_stream |> filter(fn(x) { x > 0 })
let taken_stream = repeated_stream |> take(5)
let concatenated_stream = pure(1) |> concat(pure(2))
```### Consuming Streams
```gleam
import gs.{fold, to_list, println, debug}let sum = repeated_stream |> take(5) |> fold(0, fn(acc, x) { acc + x })
let list = repeated_stream |> take(5) |> to_list
let printed_stream = pure("Hello, world!") |> println
let debugged_stream = pure(42) |> debug
```### Advanced Usage
```gleam
import gs.{chunks, tap, zip, zip_with, zip_all, zip_all_with}let chunked_stream = repeated_stream |> take(10) |> chunks(3)
let tapped_stream = repeated_stream |> tap(fn(x) { io.println(x) })
let zipped_stream = pure(1) |> zip(pure(2))
let zipped_with_stream = pure(1) |> zip_with(pure(2), fn(x, y) { x + y })
let zipped_all_stream = pure(1) |> zip_all(empty())
let zipped_all_with_stream = pure(1) |> zip_all_with(empty(), fn(x, y) { #(x, y) })
```Further documentation can be found at .
## License
This project is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for details.
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
```