Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
inoas committed Dec 14, 2024
1 parent 52a0d41 commit 9d8be28
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

<!-- ## [Unreleased] -->

## [2.0.0] - 2024-12-14

- Removed `given` function prefixes from most functions to cut down import
boilerplate and reduce local namespace pollution.

## [1.0.0] - 2024-12-14

- Initial release.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ gleam add given@1
## Usage

```gleam
import given.{
given, given_error_in, given_none_in, given_ok_in, given_some_in, not_given,
}
import given.{given, not_given}
import gleam/io
import gleam/option.{None, Some}
Expand Down Expand Up @@ -80,7 +78,7 @@ pub fn not_given_example() {
pub fn given_ok_in_example() {
{
let result = Ok("Hello Joe!")
use ok_value <- given_ok_in(result, else_return: fn(error_value) {
use ok_value <- given.ok_in(result, else_return: fn(error_value) {
error_value
})
// …user handles Ok value here…
Expand All @@ -95,7 +93,7 @@ pub fn given_ok_in_example() {
pub fn given_error_in_example() {
{
let result = Error("Memory exceeded!")
use error_value <- given_error_in(result, else_return: fn(ok_value) {
use error_value <- given.error_in(result, else_return: fn(ok_value) {
ok_value
})
// …user handles Error value here…
Expand All @@ -110,7 +108,7 @@ pub fn given_error_in_example() {
pub fn given_some_in_example() {
{
let option = Some("One Penny")
use some_value <- given_some_in(option, else_return: fn() { "Woof!" })
use some_value <- given.some_in(option, else_return: fn() { "Woof!" })
// …user handles Some value here…
some_value
}
Expand All @@ -123,7 +121,7 @@ pub fn given_some_in_example() {
pub fn given_none_in_example() {
{
let option = None
use <- given_none_in(option, else_return: fn(some_value) { some_value })
use <- given.none_in(option, else_return: fn(some_value) { some_value })
// …user handles None here…
"Nothing at all"
}
Expand Down
6 changes: 6 additions & 0 deletions bin/run-examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Go to the root of the project
cd "$(dirname "$0")" && cd ..

gleam run --module given/internal/examples
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "given"
version = "1.0.0"
version = "2.0.0"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
Expand Down
8 changes: 4 additions & 4 deletions src/given.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn not_given(
/// "Ok"
/// ```
///
pub fn given_ok_in(
pub fn ok_in(
result result: Result(a, e),
else_return alternative: fn(a) -> c,
otherwise consequence: fn(e) -> c,
Expand All @@ -85,7 +85,7 @@ pub fn given_ok_in(
/// "Error"
/// ```
///
pub fn given_error_in(
pub fn error_in(
result result: Result(a, e),
else_return consequence: fn(a) -> c,
otherwise alternative: fn(e) -> c,
Expand All @@ -104,7 +104,7 @@ pub fn given_error_in(
/// "Some value"
/// ```
///
pub fn given_some_in(
pub fn some_in(
option option: Option(a),
else_return consequence: fn() -> c,
otherwise alternative: fn(a) -> c,
Expand All @@ -123,7 +123,7 @@ pub fn given_some_in(
/// "None"
/// ```
///
pub fn given_none_in(
pub fn none_in(
option option: Option(a),
else_return consequence: fn(a) -> c,
otherwise alternative: fn() -> c,
Expand Down
12 changes: 5 additions & 7 deletions src/given/internal/examples.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import given.{
given, given_error_in, given_none_in, given_ok_in, given_some_in, not_given,
}
import given.{given, not_given}
import gleam/io
import gleam/option.{None, Some}

Expand Down Expand Up @@ -43,7 +41,7 @@ pub fn not_given_example() {
pub fn given_ok_in_example() {
{
let result = Ok("Hello Joe!")
use ok_value <- given_ok_in(result, else_return: fn(error_value) {
use ok_value <- given.ok_in(result, else_return: fn(error_value) {
error_value
})
// …user handles Ok value here…
Expand All @@ -58,7 +56,7 @@ pub fn given_ok_in_example() {
pub fn given_error_in_example() {
{
let result = Error("Memory exceeded!")
use error_value <- given_error_in(result, else_return: fn(ok_value) {
use error_value <- given.error_in(result, else_return: fn(ok_value) {
ok_value
})
// …user handles Error value here…
Expand All @@ -73,7 +71,7 @@ pub fn given_error_in_example() {
pub fn given_some_in_example() {
{
let option = Some("One Penny")
use some_value <- given_some_in(option, else_return: fn() { "Woof!" })
use some_value <- given.some_in(option, else_return: fn() { "Woof!" })
// …user handles Some value here…
some_value
}
Expand All @@ -86,7 +84,7 @@ pub fn given_some_in_example() {
pub fn given_none_in_example() {
{
let option = None
use <- given_none_in(option, else_return: fn(some_value) { some_value })
use <- given.none_in(option, else_return: fn(some_value) { some_value })
// …user handles None here…
"Nothing at all"
}
Expand Down
20 changes: 9 additions & 11 deletions test/given_test.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import given.{
given, given_error_in, given_none_in, given_ok_in, given_some_in, not_given,
}
import given.{given, not_given}
import gleam/option.{None, Some}
import gleeunit
import gleeunit/should
Expand Down Expand Up @@ -52,7 +50,7 @@ pub fn not_given_test() {
pub fn given_ok_in_test() {
{
let result = Ok(great)
use ok_value <- given_ok_in(result, else_return: fn(error_value) {
use ok_value <- given.ok_in(result, else_return: fn(error_value) {
error_value
})
// …user handles Ok value here…
Expand All @@ -62,7 +60,7 @@ pub fn given_ok_in_test() {

{
let result = Error(woof)
use ok_value <- given_ok_in(result, else_return: fn(error_value) {
use ok_value <- given.ok_in(result, else_return: fn(error_value) {
error_value
})
// …user handles Ok value here…
Expand All @@ -74,7 +72,7 @@ pub fn given_ok_in_test() {
pub fn given_error_in_test() {
{
let result = Error(woof)
use error_value <- given_error_in(result, else_return: fn(ok_value) {
use error_value <- given.error_in(result, else_return: fn(ok_value) {
ok_value
})
// …user handles Error value here…
Expand All @@ -84,7 +82,7 @@ pub fn given_error_in_test() {

{
let result = Ok(great)
use error_value <- given_error_in(result, else_return: fn(ok_value) {
use error_value <- given.error_in(result, else_return: fn(ok_value) {
ok_value
})
// …user handles Error value here…
Expand All @@ -96,14 +94,14 @@ pub fn given_error_in_test() {
pub fn given_some_in_test() {
{
let option = Some(great)
use some_value <- given_some_in(option, else_return: fn() { woof })
use some_value <- given.some_in(option, else_return: fn() { woof })
// …user handles Some value here…
some_value
}

{
let option = Some(great)
use some_value <- given_some_in(option, else_return: fn() { woof })
use some_value <- given.some_in(option, else_return: fn() { woof })
// …user handles Some value here…
some_value
}
Expand All @@ -112,13 +110,13 @@ pub fn given_some_in_test() {
pub fn given_none_in_test() {
{
let option = Some(great)
use <- given_none_in(option, else_return: fn(some_value) { some_value })
use <- given.none_in(option, else_return: fn(some_value) { some_value })
// …user handles None here…
woof
}
{
let option = None
use <- given_none_in(option, else_return: fn(some_value) { some_value })
use <- given.none_in(option, else_return: fn(some_value) { some_value })
// …user handles None here…
woof
}
Expand Down

0 comments on commit 9d8be28

Please sign in to comment.