### Project Setup and Execution Source: https://github.com/inoas/gleam-given/blob/main/README.md Instructions for cloning the Gleam Given project repository and running the provided examples. It also includes commands for development tasks like running the project and tests. ```shell git clone https://github.com/inoas/gleam-given.git bin/run-examples ``` ```shell gleam run # Run the project gleam test # Run the tests ``` -------------------------------- ### Gleam Given: Main Function Examples Source: https://github.com/inoas/gleam-given/blob/main/README.md The main function orchestrates the execution of various example functions from the Gleam Given library. Each example demonstrates a specific conditional pattern like `given_that`, `given_any`, `given_all`, `given_not`, `given_when`, `given_empty`, `given_non_empty`, `given_ok`, `given_error`, `given_some`, and `given_none`. ```gleam pub fn main() { given_that_example() |> echo // "💡 Bright!" given_any_example() |> echo // "At least admin or editor" given_all_example() |> echo // "Not both active and confirmed" given_not_example() |> echo // "👌 Access granted..." given_any_not_example() |> echo // "User has no special role!" given_all_not_example() |> echo // "Obsolete model detected." given_when_example() |> echo // "Indeed an Admin" given_when_not_example() |> echo // "Not an Admin" given_empty_example() |> echo // "Empty!" given_non_empty_example() |> echo // "Non-empty!" given_ok_example() |> echo // "Hello Joe, again!" given_any_ok_example() |> echo // "At least some OKs" given_all_ok_example() |> echo // "Some Errors" given_error_example() |> echo // "Memory exhausted, again!" given_any_error_example() |> echo // "Good" given_all_error_example() |> echo // "Meh" given_some_example() |> echo // "One More Penny" given_any_some_example() |> echo // "We found some Gold!" given_all_some_example() |> echo // "Nothing found..." given_none_example() |> echo // "None, e.g. Still nothing" given_any_none_example() |> echo // "The system detected Some-things." given_all_none_example() |> echo // "There is something out there..." } ``` -------------------------------- ### Install Given Library Source: https://github.com/inoas/gleam-given/blob/main/README.md This snippet shows the command to add the 'given' library, version 5, to a Gleam project using the Gleam package manager. ```sh gleam add given@5 ``` -------------------------------- ### Gleam Given: All None Example Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates the `given.all_none` function, which handles cases where all elements in a list are None. It returns a specific string if all elements are None, otherwise it executes a provided function. ```gleam use <- given.all_none(in: options, else_return: fn(_somes, _nones_count) { "There is something out there..." }) // …handle all None values here… "There is nothing out there..." } ``` -------------------------------- ### Gleam: Handling Empty Collections with `given.empty` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates executing a block when a list is empty using `given.empty`. It takes a list and a function to return if the list is empty. ```gleam import given pub fn given_empty_example() { let list = [] use <- given.empty(list, return: fn() { "Empty!" }) // …handle case where user is non-empty… "Non-empty!" } ``` -------------------------------- ### Gleam: Handling `None` Values with `given.none` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates executing a block when an `Option` is `None` using `given.none`. It takes an `Option` type and an `else_return` function for `Some` cases. ```gleam import gleam/option.{None, Some} import given pub fn given_none_example() { let an_option = None use <- given.none(in: an_option, else_return: fn(_some_value) { "Some value" }) // …handle None here… "None, e.g. Still nothing!" } ``` -------------------------------- ### Gleam: Checking All Conditions with `given.all` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates checking if all conditions in a list are true using `given.all`. It takes a list of booleans and a function to return if all are true. ```gleam import given pub fn given_all_example() { let is_active = True let is_confirmed = False use <- given.all([is_active, is_confirmed], return: fn() { "Ready, steady, go!" }) // …else handle case where user is not both active and confirmed… "Not both active and confirmed" } ``` -------------------------------- ### Gleam: Checking Any Condition with `given.any` Source: https://github.com/inoas/gleam-given/blob/main/README.md Illustrates checking if at least one condition in a list is true using `given.any`. It takes a list of booleans and a function to return if any are true. ```gleam import given pub fn given_any_example() { let is_admin = False let is_editor = True use <- given.any([is_admin, is_editor], return: fn() { "At least admin or editor" }) // …else handle case where user has no special role… "Got nothing to say 🤷‍♂️" } ``` -------------------------------- ### Gleam: Handling `Ok` Results with `given.ok` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates extracting the value from an `Ok` result using `given.ok`. It takes a `Result` type and an `else_return` function for `Error` cases. ```gleam import given pub fn given_ok_example() { let a_result = Ok("Hello Joe, again!") use ok_value <- given.ok(in: a_result, else_return: fn(_error_value) { "Error value" }) // …handle Ok value here… ok_value } ``` -------------------------------- ### Gleam: Handling All `Ok` Results with `given.all_ok` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows checking if all `Result`s in a list are `Ok` using `given.all_ok`. It returns the `Ok` values and handles cases where there are `Error`s. ```gleam import given pub fn given_all_ok_example() { let results = [Ok("Great"), Error("Bad")] use _oks <- given.all_ok(in: results, else_return: fn(_oks, _errors) { "Some Errors" }) // …handle all OKs here… "All OKs" } ``` -------------------------------- ### Gleam: Handling Non-Empty Collections with `given.non_empty` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows executing a block when a list is not empty using `given.non_empty`. It takes a list and a function to return if the list is not empty. ```gleam import given pub fn given_non_empty_example() { let list = [1] use <- given.non_empty(list, return: fn() { "Non-empty!" }) // …handle case where user is empty… "Empty!" } ``` -------------------------------- ### Gleam: Handling `Some` Values with `given.some` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates extracting the value from an `Option::Some` using `given.some`. It takes an `Option` type and an `else_return` function for `None` cases. ```gleam import gleam/option.{None, Some} import given pub fn given_some_example() { let an_option = Some("One More Penny") use some_value <- given.some(in: an_option, else_return: fn() { "Woof!" }) // …handle Some value here… some_value } ``` -------------------------------- ### Gleam: Handling Any `None` Values with `given.any_none` Source: https://github.com/inoas/gleam-given/blob/main/README.md Illustrates checking if at least one `Option` in a list is `None` using `given.any_none`. It returns the `Some` values and the count of `None` values. ```gleam import gleam/option.{None, Some} import given pub fn given_any_none_example() { let options = [Some("One"), None] use _somes, _none_count <- given.any_none( in: options, else_return: fn(_somes) { "Only Nones Here!" }, ) // …handle at least some None values here… "The system detected Some-things." } ``` -------------------------------- ### Gleam: Handling Any `Ok` Results with `given.any_ok` Source: https://github.com/inoas/gleam-given/blob/main/README.md Illustrates checking if at least one `Result` in a list is `Ok` using `given.any_ok`. It returns the `Ok` values and the count of `Error` values. ```gleam import given pub fn given_any_ok_example() { let results = [Ok("Great"), Error("Bad")] use _oks, _errors <- given.any_ok(in: results, else_return: fn(_errors) { "All Errors" }) // …handle at least some OKs here… "At least some OKs" } ``` -------------------------------- ### Gleam: Handling All `Some` Values with `given.all_some` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows checking if all `Option`s in a list are `Some` using `given.all_some`. It returns the `Some` values and handles cases where there are `None`s. ```gleam import gleam/option.{None, Some} import given pub fn given_all_some_example() { let options = [Some("One"), None] use _somes <- given.all_some( in: options, else_return: fn(_somes, _nones_count) { "Nothing found..." }, ) // …handle all Some values here… "There is Gold everywhere!" } ``` -------------------------------- ### Gleam: Handling Any `Some` Values with `given.any_some` Source: https://github.com/inoas/gleam-given/blob/main/README.md Illustrates checking if at least one `Option` in a list is `Some` using `given.any_some`. It returns the `Some` values and the count of `None` values. ```gleam import gleam/option.{None, Some} import given pub fn given_any_some_example() { let options = [Some("One"), None] use _somes, _nones_count <- given.any_some( in: options, else_return: fn(_nones_count) { "Just rocks here, move on..." }, ) // …handle at least some None values here… "We found some Gold!" } ``` -------------------------------- ### Gleam: Conditional Execution with `given.when` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates executing a block based on a function's return value using `given.when`. It takes a function that returns a boolean and an `else_return` function. ```gleam import given pub fn given_when_example() { let enabled = fn() { True } use <- given.when(enabled, else_return: fn() { "Not an Admin" }) // …handle case where user is an Admin… "Indeed an Admin" } ``` -------------------------------- ### Gleam: Checking All False Conditions with `given.all_not` Source: https://github.com/inoas/gleam-given/blob/main/README.md Illustrates checking if all conditions in a list are false using `given.all_not`. It takes a list of booleans and a function to return if all are false. ```gleam import given pub fn given_all_not_example() { let is_human = False let is_robot = False use <- given.all_not([is_human, is_robot], return: fn() { "Obsolete model detected." }) // …else handle case where user is neither active nor confirmed… "I am a Cylon!" } ``` -------------------------------- ### Gleam: Handling All `None` Values with `given.all_none` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows checking if all `Option`s in a list are `None` using `given.all_none`. It returns the `Some` values and the count of `None` values, handling cases where there are `Some`s. ```gleam import gleam/option.{None, Some} import given pub fn given_all_none_example() { let options = [Some("One"), None] ``` -------------------------------- ### Gleam: Checking Any False Condition with `given.any_not` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows how to check if at least one condition in a list is false using `given.any_not`. It takes a list of booleans and a function to return if any are false. ```gleam import given pub fn given_any_not_example() { let is_admin = False let is_editor = True use <- given.any_not([is_admin, is_editor], return: fn() { "At least either Admin or Editor!" }) // …else handle case where user has no special role… "User has no special role!" } ``` -------------------------------- ### Gleam: Guarding Against Conditions with `given.not` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows how to execute a block of code only if a condition is false using `given.not`. It takes a boolean condition and a function to return if the condition is not met. ```gleam import given pub fn given_not_example() { // Fetch this from some database let has_admin_role = True use <- given.not(has_admin_role, return: fn() { "✋ Denied!" }) // …else handle case where they are admin here… "👌 Access granted..." } ``` -------------------------------- ### Gleam: Conditional Execution with `given.that` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates how to execute a block of code only if a condition is true using `given.that`. It takes a boolean condition and a function to return if the condition is met. ```gleam import given pub fn given_that_example() { let user_understood = True use <- given.that(user_understood, return: fn() { "💡 Bright!" }) // …else handle case where user did not understand here… "🤯 Woof!" } ``` -------------------------------- ### Gleam: Guarding Against Conditions with `given.when_not` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows executing a block based on a function's return value being false using `given.when_not`. It takes a function that returns a boolean and an `else_return` function. ```gleam import given pub fn given_when_not_example() { let enabled = fn() { False } use <- given.when_not(enabled, else_return: fn() { "Indeed an Admin" }) // …handle case where user is not an Admin… "Not an Admin" } ``` -------------------------------- ### Gleam: Handling Any `Error` Results with `given.any_error` Source: https://github.com/inoas/gleam-given/blob/main/README.md Illustrates checking if at least one `Result` in a list is `Error` using `given.any_error`. It returns the `Error` values and the count of `Ok` values. ```gleam import given pub fn given_any_error_example() { let results = [Ok("Good"), Error("Bad")] use _oks, _errors <- given.any_error(in: results, else_return: fn(_oks) { "Bad" }) // …handle at least some Errors here… "Good" } ``` -------------------------------- ### Gleam: Handling All `Error` Results with `given.all_error` Source: https://github.com/inoas/gleam-given/blob/main/README.md Shows checking if all `Result`s in a list are `Error` using `given.all_error`. It returns the `Error` values and handles cases where there are `Ok`s. ```gleam import given pub fn given_all_error_example() { { let results = [Ok("Nice"), Error("Meh")] use _errors <- given.all_error(in: results, else_return: fn(_oks, _errors) { "Meh" }) // …handle all errors here… "Nice" } } ``` -------------------------------- ### Gleam: Handling `Error` Results with `given.error` Source: https://github.com/inoas/gleam-given/blob/main/README.md Demonstrates extracting the value from an `Error` result using `given.error`. It takes a `Result` type and an `else_return` function for `Ok` cases. ```gleam import given pub fn given_error_example() { let a_result = Error("Memory exhausted, again!") use error_value <- given.error(in: a_result, else_return: fn(_ok_value) { "Ok value" }) // …handle Error value here… error_value } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.