Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sporto/gleam_string_builder
A Gleam library for building strings
https://github.com/sporto/gleam_string_builder
gleam
Last synced: about 1 month ago
JSON representation
A Gleam library for building strings
- Host: GitHub
- URL: https://github.com/sporto/gleam_string_builder
- Owner: sporto
- License: apache-2.0
- Created: 2020-12-30T03:04:53.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-03T00:31:05.000Z (almost 4 years ago)
- Last Synced: 2024-05-09T07:11:45.984Z (8 months ago)
- Topics: gleam
- Language: Erlang
- Homepage: https://hexdocs.pm/gleam_string_builder
- Size: 26.4 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gleam_string_builder
![test](https://github.com/sporto/gleam_string_builder/workflows/test/badge.svg)
A Gleam library for building strings
```rust
let formatter =
sb.new
|> sb.string("The winner is ")
|> sb.arg_string
|> sb.string(" with ")
|> sb.arg_int
|> sb.string(" points!!")
|> sb.end2formatter("Sam", 12)
==
"The winner is Sam with 12 points!!"
```## Custom formatter
A custom formatter is a function that takes a callback and then returns another function that calls that callback with a string.
```rust
fn custom_formatter(callback) {
fn(state: State) {
let str = state_to_string(state)
callback(str)
}
}
```Then you can add this custom formatter to a pipeline using `compose`.
```rust
import string_builder as sblet formatter =
sb.new
|> sb.string("The current state is ")
|> sb.compose(custom_formatter)
|> sb.string("!")
|> sb.end1formatter(Done)
```## Installation
This package can be installed by adding `gleam_string_builder` to your `rebar.config` dependencies:
```erlang
{deps, [
gleam_string_builder
]}.
```