### Install stdin Package with Gleam Source: https://github.com/olian04/gleam_stdin/blob/main/README.md Installs the stdin package into your Gleam project. This command should be run from your project's root directory. ```shell gleam add stdin ``` -------------------------------- ### Count Non-Empty Lines from stdin in Gleam Source: https://context7.com/olian04/gleam_stdin/llms.txt Counts the total number of non-empty lines read from standard input. This example showcases the use of `yielder.filter` to prepare data and `yielder.length` for aggregation. ```gleam import gleam/int import gleam/io import gleam/string import gleam/yielder import stdin pub fn main() { let count = stdin.read_lines() |> yielder.filter(fn(line) { string.trim(line) != "" }) |> yielder.length() io.println("Total lines: " <> int.to_string(count)) } ``` -------------------------------- ### Process stdin Lines with Transformations in Gleam Source: https://context7.com/olian04/gleam_stdin/llms.txt Reads lines from stdin, filters out empty lines, converts remaining lines to uppercase, and prints them to standard output. This example demonstrates chaining yielder operations like `filter` and `map`. ```gleam import gleam/io import gleam/string import gleam/yielder import stdin pub fn main() { stdin.read_lines() |> yielder.filter(fn(line) { string.trim(line) != "" }) |> yielder.map(string.uppercase) |> yielder.each(io.println) } ``` -------------------------------- ### Grep-like Operation on stdin in Gleam Source: https://context7.com/olian04/gleam_stdin/llms.txt Implements a grep-like functionality to filter and print lines from standard input that contain a specific pattern. It uses `yielder.index` to get line numbers and `yielder.filter` for pattern matching. ```gleam import gleam/int import gleam/io import gleam/string import gleam/yielder import stdin pub fn grep(pattern: String) { stdin.read_lines() |> yielder.index() |> yielder.filter(fn(indexed_line) { let #(line, _index) = indexed_line string.contains(line, pattern) }) |> yielder.each(fn(indexed_line) { let #(line, index) = indexed_line io.println(int.to_string(index + 1) <> ": " <> line) }) } pub fn main() { grep("error") } ``` -------------------------------- ### Run Development Tests Source: https://github.com/olian04/gleam_stdin/blob/main/README.md Executes the development test script for the stdin package. This is used to ensure the package functions correctly during development. ```shell ./run_test.sh ``` -------------------------------- ### Read and Echo Stdin Lines in Gleam Source: https://github.com/olian04/gleam_stdin/blob/main/README.md Reads all lines from standard input using `stdin.read_lines()` and converts the resulting iterator to a list. The `echo` function then prints these lines to the console. This demonstrates a basic usage pattern for processing stdin. ```gleam import gleam/io import gleam/yielder import stdin pub fn main() { stdin.read_lines() |> yielder.to_list |> echo } ``` -------------------------------- ### Interactive Prompt Loop using stdin in Gleam Source: https://context7.com/olian04/gleam_stdin/llms.txt Processes user input interactively in a loop until the user types 'quit'. It reads lines, trims whitespace, and echoes input back, demonstrating `yielder.take_while` for conditional processing. ```gleam import gleam/io import gleam/string import gleam/yielder import stdin pub fn main() { io.println("Enter commands (type 'quit' to exit):") stdin.read_lines() |> yielder.map(string.trim) |> yielder.take_while(fn(line) { line != "quit" }) |> yielder.each(fn(line) { io.println("You entered: " <> line) }) io.println("Goodbye!") } ``` -------------------------------- ### Read All Lines from stdin in Gleam Source: https://context7.com/olian04/gleam_stdin/llms.txt Reads all lines from standard input until EOF is reached and converts them into a list. Each line is then echoed back to standard output. This function uses the `stdin.read_lines()` yielder and `yielder.to_list()`. ```gleam import gleam/io import gleam/yielder import stdin pub fn main() { // Read all lines from stdin and convert to list let lines = stdin.read_lines() |> yielder.to_list() // Echo each line back to stdout lines |> list.each(io.println) } ``` -------------------------------- ### Word Frequency Counter using stdin in Gleam Source: https://context7.com/olian04/gleam_stdin/llms.txt Calculates the frequency of each word from standard input. It splits lines into words, filters empty strings, and uses `yielder.fold` with a dictionary to count occurrences. ```gleam import gleam/dict import gleam/io import gleam/list import gleam/string import gleam/yielder import stdin pub fn main() { stdin.read_lines() |> yielder.flat_map(fn(line) { string.split(line, " ") |> yielder.from_list() }) |> yielder.map(string.trim) |> yielder.filter(fn(word) { word != "" }) |> yielder.fold(dict.new(), fn(acc, word) { dict.upsert(acc, word, fn(existing) { case existing { Some(count) -> count + 1 None -> 1 } }) }) |> dict.to_list() |> list.each(fn(pair) { let #(word, count) = pair io.println(word <> ": " <> int.to_string(count)) }) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.