aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gleam/atom.gleam8
-rw-r--r--src/gleam/dynamic.gleam49
-rw-r--r--src/gleam/float.gleam25
-rw-r--r--src/gleam/int.gleam18
-rw-r--r--src/gleam/iodata.gleam37
-rw-r--r--src/gleam/list.gleam162
-rw-r--r--src/gleam/map.gleam80
-rw-r--r--src/gleam/result.gleam5
-rw-r--r--src/gleam/should.gleam21
-rw-r--r--src/gleam/string.gleam77
-rw-r--r--test/gleam/atom_test.gleam14
-rw-r--r--test/gleam/bool_test.gleam28
-rw-r--r--test/gleam/dynamic_test.gleam126
-rw-r--r--test/gleam/float_test.gleam92
-rw-r--r--test/gleam/function_test.gleam31
-rw-r--r--test/gleam/int_test.gleam62
-rw-r--r--test/gleam/iodata_test.gleam44
-rw-r--r--test/gleam/list_test.gleam293
-rw-r--r--test/gleam/map_test.gleam227
-rw-r--r--test/gleam/order_test.gleam66
-rw-r--r--test/gleam/pair_test.gleam42
-rw-r--r--test/gleam/result_test.gleam52
-rw-r--r--test/gleam/string_test.gleam90
23 files changed, 783 insertions, 866 deletions
diff --git a/src/gleam/atom.gleam b/src/gleam/atom.gleam
index 8e9cb04..b101139 100644
--- a/src/gleam/atom.gleam
+++ b/src/gleam/atom.gleam
@@ -13,7 +13,7 @@
/// user input into atoms) we may hit the max limit of atoms and cause the
/// virtual machine to crash.
///
-pub external type Atom;
+pub external type Atom
/// An error returned when no atom is found in the virtual machine's atom table
/// for a given string when calling the [`from_string`](#from_string) function.
@@ -35,7 +35,7 @@ pub type FromStringError {
/// Error(AtomNotLoaded)
///
pub external fn from_string(String) -> Result(Atom, FromStringError) =
- "gleam_stdlib" "atom_from_string";
+ "gleam_stdlib" "atom_from_string"
/// Create an atom from a string, inserting a new value into the virtual
/// machine's atom table if an atom does not already exist for the given
@@ -47,7 +47,7 @@ pub external fn from_string(String) -> Result(Atom, FromStringError) =
/// virtual machine to crash!
///
pub external fn create_from_string(String) -> Atom =
- "gleam_stdlib" "atom_create_from_string";
+ "gleam_stdlib" "atom_create_from_string"
/// Retuns a `String` corresponding to the text representation of the given
/// `Atom`.
@@ -59,4 +59,4 @@ pub external fn create_from_string(String) -> Atom =
/// "ok"
///
pub external fn to_string(Atom) -> String =
- "gleam_stdlib" "atom_to_string";
+ "gleam_stdlib" "atom_to_string"
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam
index 4355e59..bab30d3 100644
--- a/src/gleam/dynamic.gleam
+++ b/src/gleam/dynamic.gleam
@@ -5,11 +5,12 @@ import gleam/result
/// `Dynamic` data is data that we don"t know the type of yet.
/// We likely get data like this from interop with Erlang, or from
/// IO with the outside world.
-pub external type Dynamic;
+pub external type Dynamic
/// Convert any Gleam data into `Dynamic` data.
///
-pub external fn from(a) -> Dynamic = "gleam_stdlib" "identity";
+pub external fn from(a) -> Dynamic =
+ "gleam_stdlib" "identity"
/// Unsafely cast a Dynamic value into any other type.
///
@@ -18,7 +19,8 @@ pub external fn from(a) -> Dynamic = "gleam_stdlib" "identity";
///
/// If you can avoid using this function, do!
///
-pub external fn unsafe_coerce(Dynamic) -> a = "gleam_stdlib" "identity";
+pub external fn unsafe_coerce(Dynamic) -> a =
+ "gleam_stdlib" "identity"
/// Check to see whether a Dynamic value is a string, and return the string if
/// it is.
@@ -31,8 +33,8 @@ pub external fn unsafe_coerce(Dynamic) -> a = "gleam_stdlib" "identity";
/// > string(from(123))
/// Error("Expected a String, got `123`")
///
-pub external fn string(from: Dynamic) -> Result(String, String)
- = "gleam_stdlib" "decode_string"
+pub external fn string(from: Dynamic) -> Result(String, String) =
+ "gleam_stdlib" "decode_string"
/// Check to see whether a Dynamic value is an int, and return the int if it
/// is.
@@ -45,8 +47,8 @@ pub external fn string(from: Dynamic) -> Result(String, String)
/// > int(from("Hello"))
/// Error("Expected an Int, got `\"Hello World\"`")
///
-pub external fn int(from: Dynamic) -> Result(Int, String)
- = "gleam_stdlib" "decode_int"
+pub external fn int(from: Dynamic) -> Result(Int, String) =
+ "gleam_stdlib" "decode_int"
/// Check to see whether a Dynamic value is an float, and return the float if
/// it is.
@@ -59,8 +61,8 @@ pub external fn int(from: Dynamic) -> Result(Int, String)
/// > float(from(123))
/// Error("Expected a Float, got `123`")
///
-pub external fn float(from: Dynamic) -> Result(Float, String)
- = "gleam_stdlib" "decode_float"
+pub external fn float(from: Dynamic) -> Result(Float, String) =
+ "gleam_stdlib" "decode_float"
/// Check to see whether a Dynamic value is an atom, and return the atom if
/// it is.
@@ -74,8 +76,8 @@ pub external fn float(from: Dynamic) -> Result(Float, String)
/// > atom(from(123))
/// Error("Expected an Atom, got `123`")
///
-pub external fn atom(from: Dynamic) -> Result(atom.Atom, String)
- = "gleam_stdlib" "decode_atom"
+pub external fn atom(from: Dynamic) -> Result(atom.Atom, String) =
+ "gleam_stdlib" "decode_atom"
/// Check to see whether a Dynamic value is an bool, and return the bool if
/// it is.
@@ -88,8 +90,8 @@ pub external fn atom(from: Dynamic) -> Result(atom.Atom, String)
/// > bool(from(123))
/// Error("Expected a Bool, got `123`")
///
-pub external fn bool(from: Dynamic) -> Result(Bool, String)
- = "gleam_stdlib" "decode_bool"
+pub external fn bool(from: Dynamic) -> Result(Bool, String) =
+ "gleam_stdlib" "decode_bool"
/// Check to see whether a Dynamic value is a function that takes no arguments,
/// and return the function if it is.
@@ -104,11 +106,11 @@ pub external fn bool(from: Dynamic) -> Result(Bool, String)
/// > thunk(from(123))
/// Error("Expected a zero arity function, got `123`")
///
-pub external fn thunk(from: Dynamic) -> Result(fn() -> Dynamic, String)
- = "gleam_stdlib" "decode_thunk"
+pub external fn thunk(from: Dynamic) -> Result(fn() -> Dynamic, String) =
+ "gleam_stdlib" "decode_thunk"
-external fn list_dynamic(from: Dynamic) -> Result(List(Dynamic), String)
- = "gleam_stdlib" "decode_list"
+external fn list_dynamic(from: Dynamic) -> Result(List(Dynamic), String) =
+ "gleam_stdlib" "decode_list"
/// Check to see whether a Dynamic value is a list, and return the list if it
/// is.
@@ -130,7 +132,7 @@ pub fn list(
) -> Result(List(inner), String) {
dynamic
|> list_dynamic
- |> result.then(_, list_mod.traverse(_, decoder_type))
+ |> result.then(list_mod.traverse(_, decoder_type))
}
/// Check to see if a Dynamic value is a map with a specific field, and return
@@ -147,8 +149,8 @@ pub fn list(
/// > field(from(123), "Hello")
/// Error("Expected a map with key `\"Hello\"`, got an Int")
///
-pub external fn field(from: Dynamic, named: a) -> Result(Dynamic, String)
- = "gleam_stdlib" "decode_field"
+pub external fn field(from: Dynamic, named: a) -> Result(Dynamic, String) =
+ "gleam_stdlib" "decode_field"
/// Check to see if the Dynamic value is a tuple large enough to have a certain
/// index, and return the value of that index if it is.
@@ -164,5 +166,8 @@ pub external fn field(from: Dynamic, named: a) -> Result(Dynamic, String)
/// > element(from(""), 2)
/// Error("Expected a Tuple, got a binary")
///
-pub external fn element(from: Dynamic, position: Int) -> Result(Dynamic, String)
- = "gleam_stdlib" "decode_element"
+pub external fn element(
+ from: Dynamic,
+ position: Int,
+) -> Result(Dynamic, String) =
+ "gleam_stdlib" "decode_element"
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam
index 918ecc2..6556204 100644
--- a/src/gleam/float.gleam
+++ b/src/gleam/float.gleam
@@ -15,8 +15,8 @@ pub type Float =
/// > parse("ABC")
/// None
///
-pub external fn parse(String) -> Option(Float)
- = "gleam_stdlib" "parse_float";
+pub external fn parse(String) -> Option(Float) =
+ "gleam_stdlib" "parse_float"
/// Return the string representation of the provided float.
///
@@ -39,11 +39,10 @@ pub fn to_string(f: Float) -> String {
pub fn compare(a: Float, with b: Float) -> Order {
case a == b {
True -> order.Eq
- False ->
- case a <. b {
- True -> order.Lt
- False -> order.Gt
- }
+ False -> case a <. b {
+ True -> order.Lt
+ False -> order.Gt
+ }
}
}
@@ -82,7 +81,8 @@ pub fn max(a: Float, b: Float) -> Float {
/// > ceiling(2.3)
/// 3.0
///
-pub external fn ceiling(Float) -> Float = "math" "ceil";
+pub external fn ceiling(Float) -> Float =
+ "math" "ceil"
/// Rounds the value to the next lowest whole number as a float.
///
@@ -91,7 +91,8 @@ pub external fn ceiling(Float) -> Float = "math" "ceil";
/// > floor(2.3)
/// 2.0
///
-pub external fn floor(Float) -> Float = "math" "floor";
+pub external fn floor(Float) -> Float =
+ "math" "floor"
/// Rounds the value to the nearest whole number as an int.
///
@@ -103,7 +104,8 @@ pub external fn floor(Float) -> Float = "math" "floor";
/// > round(2.5)
/// 3
///
-pub external fn round(Float) -> Int = "erlang" "round";
+pub external fn round(Float) -> Int =
+ "erlang" "round"
/// Returns the value as an int, truncating all decimal digits.
///
@@ -112,4 +114,5 @@ pub external fn round(Float) -> Int = "erlang" "round";
/// > truncate(2.4343434847383438)
/// 2
///
-pub external fn truncate(Float) -> Int = "erlang" "trunc";
+pub external fn truncate(Float) -> Int =
+ "erlang" "trunc"
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam
index a0a0462..7399aac 100644
--- a/src/gleam/int.gleam
+++ b/src/gleam/int.gleam
@@ -14,7 +14,8 @@ pub type Int =
/// > parse("ABC")
/// Error(Nil)
///
-pub external fn parse(String) -> Option(Int) = "gleam_stdlib" "parse_int";
+pub external fn parse(String) -> Option(Int) =
+ "gleam_stdlib" "parse_int"
/// Print a given int to a string.
///
@@ -23,7 +24,8 @@ pub external fn parse(String) -> Option(Int) = "gleam_stdlib" "parse_int";
/// > to_string(2)
/// "2"
///
-pub external fn to_string(Int) -> String = "erlang" "integer_to_binary"
+pub external fn to_string(Int) -> String =
+ "erlang" "integer_to_binary"
/// Print a given int to a string using the base number provided.
///
@@ -38,7 +40,8 @@ pub external fn to_string(Int) -> String = "erlang" "integer_to_binary"
/// > to_base_string(48, 36)
/// "1C"
///
-pub external fn to_base_string(Int, Int) -> String = "erlang" "integer_to_binary"
+pub external fn to_base_string(Int, Int) -> String =
+ "erlang" "integer_to_binary"
/// Compares two ints, returning an order.
///
@@ -56,11 +59,10 @@ pub external fn to_base_string(Int, Int) -> String = "erlang" "integer_to_binary
pub fn compare(a: Int, with b: Int) -> Order {
case a == b {
True -> order.Eq
- False ->
- case a < b {
- True -> order.Lt
- False -> order.Gt
- }
+ False -> case a < b {
+ True -> order.Lt
+ False -> order.Gt
+ }
}
}
diff --git a/src/gleam/iodata.gleam b/src/gleam/iodata.gleam
index 5310b5e..fe24974 100644
--- a/src/gleam/iodata.gleam
+++ b/src/gleam/iodata.gleam
@@ -9,56 +9,56 @@
/// using minimal memory, and then can be efficiently converted to a string
/// using the `to_string` function.
///
-pub external type Iodata;
+pub external type Iodata
/// Prepend a String onto the start of some Iodata.
///
/// Runs in constant time.
///
pub external fn prepend(to: Iodata, prefix: String) -> Iodata =
- "gleam_stdlib" "iodata_prepend";
+ "gleam_stdlib" "iodata_prepend"
/// Append a String onto the end of some Iodata.
///
/// Runs in constant time.
///
pub external fn append(to: Iodata, suffix: String) -> Iodata =
- "gleam_stdlib" "iodata_append";
+ "gleam_stdlib" "iodata_append"
/// Prepend some Iodata onto the start of another.
///
/// Runs in constant time.
///
pub external fn prepend_iodata(to: Iodata, prefix: Iodata) -> Iodata =
- "gleam_stdlib" "iodata_prepend";
+ "gleam_stdlib" "iodata_prepend"
/// Append some Iodata onto the end of another.
///
/// Runs in constant time.
///
pub external fn append_iodata(to: Iodata, suffix: Iodata) -> Iodata =
- "gleam_stdlib" "iodata_append";
+ "gleam_stdlib" "iodata_append"
/// Convert a list of strings into iodata.
///
/// Runs in constant time.
///
pub external fn from_strings(List(String)) -> Iodata =
- "gleam_stdlib" "identity";
+ "gleam_stdlib" "identity"
/// Joins a list of iodata into a single iodata.
///
/// Runs in constant time.
///
pub external fn concat(List(Iodata)) -> Iodata =
- "gleam_stdlib" "identity";
+ "gleam_stdlib" "identity"
/// Convert a string into iodata.
///
/// Runs in constant time.
///
pub external fn new(String) -> Iodata =
- "gleam_stdlib" "identity";
+ "gleam_stdlib" "identity"
/// Turns an `Iodata` into a `String`
///
@@ -66,32 +66,35 @@ pub external fn new(String) -> Iodata =
/// optimised.
///
pub external fn to_string(Iodata) -> String =
- "erlang" "iolist_to_binary";
+ "erlang" "iolist_to_binary"
/// Returns the size of the Iodata in bytes.
///
pub external fn byte_size(Iodata) -> Int =
- "erlang" "iolist_size";
+ "erlang" "iolist_size"
/// Creates textual representation of the given float as iodata.
///
pub external fn from_float(Float) -> Iodata =
- "io_lib_format" "fwrite_g";
+ "io_lib_format" "fwrite_g"
/// Converts Iodata to a new Iodata where valid UTF-8 string data is
/// lowercased.
///
-pub external fn lowercase(Iodata) -> Iodata = "string" "lowercase"
+pub external fn lowercase(Iodata) -> Iodata =
+ "string" "lowercase"
/// Converts Iodata to a new Iodata where valid UTF-8 string data is
/// uppercased.
///
-pub external fn uppercase(Iodata) -> Iodata = "string" "uppercase"
+pub external fn uppercase(Iodata) -> Iodata =
+ "string" "uppercase"
/// Converts Iodata to a new Iodata where valid UTF-8 string data is
/// reversed.
///
-pub external fn reverse(Iodata) -> Iodata = "string" "reverse"
+pub external fn reverse(Iodata) -> Iodata =
+ "string" "reverse"
type Direction {
All
@@ -135,7 +138,8 @@ pub fn replace(
/// True
///
///
-pub external fn is_equal(Iodata, Iodata) -> Bool = "string" "equal"
+pub external fn is_equal(Iodata, Iodata) -> Bool =
+ "string" "equal"
/// Inspect some iodata to determine if it is equivalent to an empty string.
///
@@ -151,4 +155,5 @@ pub external fn is_equal(Iodata, Iodata) -> Bool = "string" "equal"
/// True
///
///
-pub external fn is_empty(Iodata) -> Bool = "string" "is_empty"
+pub external fn is_empty(Iodata) -> Bool =
+ "string" "is_empty"
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 67bd778..a0098a1 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -51,7 +51,8 @@ pub type LengthMismatch {
/// > length([1, 2])
/// 2
///
-pub external fn length(of: List(a)) -> Int = "erlang" "length"
+pub external fn length(of: List(a)) -> Int =
+ "erlang" "length"
/// Create a new list from a given list containing the same elements but in the
/// opposite order.
@@ -73,7 +74,8 @@ pub external fn length(of: List(a)) -> Int = "erlang" "length"
/// > reverse([1, 2])
/// [2, 1]
///
-pub external fn reverse(List(a)) -> List(a) = "lists" "reverse"
+pub external fn reverse(List(a)) -> List(a) =
+ "lists" "reverse"
/// Determine whether or not the list is empty.
///
@@ -119,7 +121,7 @@ pub fn is_empty(list: List(a)) -> Bool {
pub fn contains(list: List(a), has elem: a) -> Bool {
case list {
[] -> False
- [head | rest] -> head == elem || contains(rest, elem)
+ [head, ..rest] -> head == elem || contains(rest, elem)
}
}
@@ -139,7 +141,7 @@ pub fn contains(list: List(a), has elem: a) -> Bool {
pub fn head(list: List(a)) -> Option(a) {
case list {
[] -> result.none()
- [x | _] -> Ok(x)
+ [x, ..] -> Ok(x)
}
}
@@ -162,16 +164,16 @@ pub fn head(list: List(a)) -> Option(a) {
pub fn tail(list: List(a)) -> Option(List(a)) {
case list {
[] -> result.none()
- [_ | xs] -> Ok(xs)
+ [_, ..xs] -> Ok(xs)
}
}
fn do_filter(list: List(a), fun: fn(a) -> Bool, acc: List(a)) -> List(a) {
case list {
[] -> reverse(acc)
- [x | xs] -> {
+ [x, ..xs] -> {
let new_acc = case fun(x) {
- True -> [x | acc]
+ True -> [x, ..acc]
False -> acc
}
do_filter(xs, fun, new_acc)
@@ -197,7 +199,7 @@ pub fn filter(list: List(a), for predicate: fn(a) -> Bool) -> List(a) {
fn do_map(list: List(a), fun: fn(a) -> b, acc: List(b)) -> List(b) {
case list {
[] -> reverse(acc)
- [x | xs] -> do_map(xs, fun, [fun(x) | acc])
+ [x, ..xs] -> do_map(xs, fun, [fun(x), ..acc])
}
}
@@ -221,7 +223,7 @@ fn do_index_map(
) -> List(b) {
case list {
[] -> reverse(acc)
- [x | xs] -> do_index_map(xs, fun, index + 1, [fun(index, x) | acc])
+ [x, ..xs] -> do_index_map(xs, fun, index + 1, [fun(index, x), ..acc])
}
}
@@ -240,7 +242,6 @@ pub fn index_map(list: List(a), with fun: fn(Int, a) -> b) -> List(b) {
do_index_map(list, fun, 0, [])
}
-
fn do_traverse(
list: List(a),
fun: fn(a) -> Result(b, e),
@@ -248,11 +249,10 @@ fn do_traverse(
) -> Result(List(b), e) {
case list {
[] -> Ok(reverse(acc))
- [x | xs] ->
- case fun(x) {
- Ok(y) -> do_traverse(xs, fun, [y | acc])
- Error(error) -> Error(error)
- }
+ [x, ..xs] -> case fun(x) {
+ Ok(y) -> do_traverse(xs, fun, [y, ..acc])
+ Error(error) -> Error(error)
+ }
}
}
@@ -306,22 +306,20 @@ pub fn traverse(
pub fn drop(from list: List(a), up_to n: Int) -> List(a) {
case n <= 0 {
True -> list
- False ->
- case list {
- [] -> []
- [_ | xs] -> drop(xs, n - 1)
- }
+ False -> case list {
+ [] -> []
+ [_, ..xs] -> drop(xs, n - 1)
+ }
}
}
fn do_take(list: List(a), n: Int, acc: List(a)) -> List(a) {
case n <= 0 {
True -> reverse(acc)
- False ->
- case list {
- [] -> reverse(acc)
- [x | xs] -> do_take(xs, n - 1, [x | acc])
- }
+ False -> case list {
+ [] -> reverse(acc)
+ [x, ..xs] -> do_take(xs, n - 1, [x, ..acc])
+ }
}
}
@@ -366,13 +364,13 @@ pub fn new() -> List(a) {
/// > append([1, 2], [3])
/// [1, 2, 3]
///
-pub external fn append(List(a), List(a)) -> List(a)
- = "lists" "append";
+pub external fn append(List(a), List(a)) -> List(a) =
+ "lists" "append"
fn do_flatten(lists: List(List(a)), acc: List(a)) -> List(a) {
case lists {
[] -> acc
- [l | rest] -> do_flatten(rest, append(acc, l))
+ [l, ..rest] -> do_flatten(rest, append(acc, l))
}
}
@@ -400,7 +398,7 @@ pub fn flatten(lists: List(List(a))) -> List(a) {
pub fn fold(list: List(a), from initial: b, with fun: fn(a, b) -> b) -> b {
case list {
[] -> initial
- [x | rest] -> fold(rest, fun(x, initial), fun)
+ [x, ..rest] -> fold(rest, fun(x, initial), fun)
}
}
@@ -422,7 +420,7 @@ pub fn fold_right(
) -> b {
case list {
[] -> initial
- [x | rest] -> fun(x, fold_right(rest, initial, fun))
+ [x, ..rest] -> fun(x, fold_right(rest, initial, fun))
}
}
@@ -449,11 +447,10 @@ pub fn find(
) -> Option(a) {
case haystack {
[] -> result.none()
- [x | rest] ->
- case is_desired(x) {
- True -> Ok(x)
- _ -> find(in: rest, one_that: is_desired)
- }
+ [x, ..rest] -> case is_desired(x) {
+ True -> Ok(x)
+ _ -> find(in: rest, one_that: is_desired)
+ }
}
}
@@ -480,11 +477,10 @@ pub fn find_map(
) -> Option(b) {
case haystack {
[] -> result.none()
- [x | rest] ->
- case fun(x) {
- Ok(x) -> Ok(x)
- _ -> find_map(in: rest, with: fun)
- }
+ [x, ..rest] -> case fun(x) {
+ Ok(x) -> Ok(x)
+ _ -> find_map(in: rest, with: fun)
+ }
}
}
@@ -506,8 +502,7 @@ pub fn find_map(
pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool {
case list {
[] -> True
- [x | rest] ->
- case predicate(x) {
+ [x, ..rest] -> case predicate(x) {
True -> all(rest, predicate)
_ -> False
}
@@ -535,8 +530,7 @@ pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool {
pub fn any(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool {
case list {
[] -> False
- [x | rest] ->
- case predicate(x) {
+ [x, ..rest] -> case predicate(x) {
False -> any(rest, predicate)
_ -> True
}
@@ -566,7 +560,7 @@ pub fn zip(xs: List(a), ys: List(b)) -> List(tuple(a, b)) {
case xs, ys {
[], _ -> []
_, [] -> []
- [x | xs], [y | ys] -> [tuple(x, y) | zip(xs, ys)]
+ [x, ..xs], [y, ..ys] -> [tuple(x, y), ..zip(xs, ys)]
}
}
@@ -588,7 +582,10 @@ pub fn zip(xs: List(a), ys: List(b)) -> List(tuple(a, b)) {
/// > strict_zip([1, 2], [3, 4])
/// Ok([tuple(1, 3), tuple(2, 4)])
///
-pub fn strict_zip(l1: List(a), l2: List(b)) -> Result(List(tuple(a, b)), LengthMismatch) {
+pub fn strict_zip(
+ l1: List(a),
+ l2: List(b),
+) -> Result(List(tuple(a, b)), LengthMismatch) {
case length(of: l1) == length(of: l2) {
True -> Ok(zip(l1, l2))
False -> Error(LengthMismatch)
@@ -610,7 +607,7 @@ pub fn strict_zip(l1: List(a), l2: List(b)) -> Result(List(tuple(a, b)), LengthM
pub fn intersperse(list: List(a), with elem: a) -> List(a) {
case list {
[] | [_] -> list
- [x | rest] -> [x | [elem | intersperse(rest, elem)]]
+ [x, ..rest] -> [x, elem, ..intersperse(rest, elem)]
}
}
@@ -630,14 +627,12 @@ pub fn intersperse(list: List(a), with elem: a) -> List(a) {
pub fn at(in list: List(a), get index: Int) -> Option(a) {
case index < 0 {
True -> result.none()
- False ->
- case list {
+ False -> case list {
[] -> result.none()
- [x | rest] ->
- case index == 0 {
- True -> Ok(x)
- False -> at(rest, index - 1)
- }
+ [x, ..rest] -> case index == 0 {
+ True -> Ok(x)
+ False -> at(rest, index - 1)
+ }
}
}
}
@@ -654,7 +649,7 @@ pub fn at(in list: List(a), get index: Int) -> Option(a) {
pub fn unique(list: List(a)) -> List(a) {
case list {
[] -> []
- [x | rest] -> [x | unique(filter(rest, fn(y) { y != x }))]
+ [x, ..rest] -> [x, ..unique(filter(rest, fn(y) { y != x }))]
}
}
@@ -662,15 +657,18 @@ fn merge_sort(a: List(a), b: List(a), compare: fn(a, a) -> Order) -> List(a) {
case a, b {
[], _ -> b
_, [] -> a
- [ax | ar], [bx | br] ->
- case compare(ax, bx) {
- order.Lt -> [ax | merge_sort(ar, b, compare)]
- _ -> [bx | merge_sort(a, br, compare)]
- }
+ [ax, ..ar], [bx, ..br] -> case compare(ax, bx) {
+ order.Lt -> [ax, ..merge_sort(ar, b, compare)]
+ _ -> [bx, ..merge_sort(a, br, compare)]
+ }
}
}
-fn do_sort(list: List(a), compare: fn(a, a) -> Order, list_length: Int) -> List(a) {
+fn do_sort(
+ list: List(a),
+ compare: fn(a, a) -> Order,
+ list_length: Int,
+) -> List(a) {
case list_length < 2 {
True -> list
False -> {
@@ -715,15 +713,15 @@ pub fn sort(list: List(a), sort_by compare: fn(a, a) -> Order) -> List(a) {
pub fn range(from start: Int, to stop: Int) -> List(Int) {
case int.compare(start, stop) {
order.Eq -> []
- order.Gt -> [start | range(start - 1, stop)]
- order.Lt -> [start | range(start + 1, stop)]
+ order.Gt -> [start, ..range(start - 1, stop)]
+ order.Lt -> [start, ..range(start + 1, stop)]
}
}
fn do_repeat(a: a, times: Int, acc: List(a)) -> List(a) {
case times <= 0 {
True -> acc
- False -> do_repeat(a, times - 1, [a | acc])
+ False -> do_repeat(a, times - 1, [a, ..acc])
}
}
@@ -744,11 +742,10 @@ pub fn repeat(item a: a, times times: Int) -> List(a) {
fn do_split(list: List(a), n: Int, taken: List(a)) -> tuple(List(a), List(a)) {
case n <= 0 {
True -> tuple(reverse(taken), list)
- False ->
- case list {
- [] -> tuple(reverse(taken), [])
- [x | xs] -> do_split(xs, n - 1, [x | taken])
- }
+ False -> case list {
+ [] -> tuple(reverse(taken), [])
+ [x, ..xs] -> do_split(xs, n - 1, [x, ..taken])
+ }
}
}
@@ -779,11 +776,10 @@ fn do_split_while(
) -> tuple(List(a), List(a)) {
case list {
[] -> tuple(reverse(acc), [])
- [x | xs] ->
- case f(x) {
- False -> tuple(reverse(acc), list)
- _ -> do_split_while(xs, f, [x | acc])
- }
+ [x, ..xs] -> case f(x) {
+ False -> tuple(reverse(acc), list)
+ _ -> do_split_while(xs, f, [x, ..acc])
+ }
}
}
@@ -808,7 +804,6 @@ pub fn split_while(
do_split_while(list, predicate, [])
}
-
/// Given a list of 2 element tuples, find the first tuple that has a given
/// key as the first element and return the second element.
///
@@ -832,11 +827,14 @@ pub fn key_find(
in keyword_list: List(tuple(k, v)),
find desired_key: k,
) -> Option(v) {
- find_map(keyword_list, fn(keyword) {
- let tuple(key, value) = keyword
- case key == desired_key {
- True -> Ok(value)
- False -> result.none()
- }
- })
+ find_map(
+ keyword_list,
+ fn(keyword) {
+ let tuple(key, value) = keyword
+ case key == desired_key {
+ True -> Ok(value)
+ False -> result.none()
+ }
+ },
+ )
}
diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam
index daaee6e..df7b71e 100644
--- a/src/gleam/map.gleam
+++ b/src/gleam/map.gleam
@@ -16,7 +16,7 @@ import gleam/result.{Option}
/// See [the Erlang map module](https://erlang.org/doc/man/maps.html) for more
/// information.
///
-pub external type Map(key, value);
+pub external type Map(key, value)
/// Determine the number of key-value pairs in the map.
/// This function runs in constant time and does not need to iterate the map.
@@ -30,8 +30,8 @@ pub external type Map(key, value);
/// 1
///
///
-pub external fn size(Map(k, v)) -> Int
- = "maps" "size"
+pub external fn size(Map(k, v)) -> Int =
+ "maps" "size"
/// Convert the map to a list of 2-element tuples `tuple(key, value)`, one for
/// each key-value pair in the map.
@@ -46,19 +46,19 @@ pub external fn size(Map(k, v)) -> Int
/// > new() |> insert("key", 0) |> to_list()
/// [tuple("key", 0)]
///
-pub external fn to_list(Map(key, value)) -> List(tuple(key, value))
- = "maps" "to_list"
+pub external fn to_list(Map(key, value)) -> List(tuple(key, value)) =
+ "maps" "to_list"
/// Convert a list of 2-element tuples `tuple(key, value)` to a map.
///
/// If two tuples have the same key the last one in the list will be the one
/// that is present in the map.
///
-pub external fn from_list(List(tuple(key, value))) -> Map(key, value)
- = "maps" "from_list"
+pub external fn from_list(List(tuple(key, value))) -> Map(key, value) =
+ "maps" "from_list"
-external fn is_key(key, Map(key, v)) -> Bool
- = "maps" "is_key"
+external fn is_key(key, Map(key, v)) -> Bool =
+ "maps" "is_key"
/// Determind whether or not a value present in the map for a given key.
///
@@ -74,11 +74,10 @@ pub fn has_key(map: Map(k, v), key: k) -> Bool {
is_key(key, map)
}
-
/// Create a fresh map that contains no values.
///
-pub external fn new() -> Map(key, value)
- = "maps" "new"
+pub external fn new() -> Map(key, value) =
+ "maps" "new"
/// Fetch a value from a map for a given key.
///
@@ -93,11 +92,11 @@ pub external fn new() -> Map(key, value)
/// > new() |> insert("a", 0) |> get("b")
/// Error(Nil)
///
-pub external fn get(from: Map(key, value), get: key) -> Option(value)
- = "gleam_stdlib" "map_get";
+pub external fn get(from: Map(key, value), get: key) -> Option(value) =
+ "gleam_stdlib" "map_get"
-external fn erl_insert(key, value, Map(key, value)) -> Map(key, value)
- = "maps" "put";
+external fn erl_insert(key, value, Map(key, value)) -> Map(key, value) =
+ "maps" "put"
/// Insert a value into the map with the given key.
///
@@ -116,9 +115,8 @@ pub fn insert(into map: Map(k, v), for key: k, insert value: v) -> Map(k, v) {
erl_insert(key, value, map)
}
-external fn erl_map_values(fn(key, a) -> b, Map(key, value))
- -> Map(key, b)
- = "maps" "map";
+external fn erl_map_values(fn(key, a) -> b, Map(key, value)) -> Map(key, b) =
+ "maps" "map"
/// Update all values in a given map by calling a given function on each key
/// and value.
@@ -146,8 +144,8 @@ pub fn map_values(in map: Map(k, v), with fun: fn(k, v) -> w) -> Map(k, w) {
/// > keys([tuple("a", 0), tuple("b", 1)])
/// ["a", "b"]
///
-pub external fn keys(Map(keys, v)) -> List(keys)
- = "maps" "keys"
+pub external fn keys(Map(keys, v)) -> List(keys) =
+ "maps" "keys"
/// Get a list of all values in a given map.
///
@@ -160,12 +158,14 @@ pub external fn keys(Map(keys, v)) -> List(keys)
/// > keys(from_list([tuple("a", 0), tuple("b", 1)]))
/// [0, 1]
///
-pub external fn values(Map(k, values)) -> List(values)
- = "maps" "values"
+pub external fn values(Map(k, values)) -> List(values) =
+ "maps" "values"
-external fn erl_filter(fn(key, value) -> Bool, Map(key, value))
- -> Map(key, value)
- = "maps" "filter";
+external fn erl_filter(
+ fn(key, value) -> Bool,
+ Map(key, value),
+) -> Map(key, value) =
+ "maps" "filter"
/// Create a new map from a given map, minus any entries that a given function
/// returns False for.
@@ -184,8 +184,8 @@ pub fn filter(in map: Map(k, v), for predicate: fn(k, v) -> Bool) -> Map(k, v) {
erl_filter(predicate, map)
}
-external fn erl_take(List(k), Map(k, v)) -> Map(k, v)
- = "maps" "with"
+external fn erl_take(List(k), Map(k, v)) -> Map(k, v) =
+ "maps" "with"
/// Create a new map from a given map, only including any entries for which the
/// keys are in a given list.
@@ -216,12 +216,11 @@ pub fn take(from map: Map(k, v), drop desired_keys: List(k)) -> Map(k, v) {
/// > merge(a, b)
/// from_list([tuple("a", 0), tuple("b", 2), tuple("c", 3)])
///
-pub external fn merge(into: Map(k, v), merge: Map(k, v)) -> Map(k, v)
- = "maps" "merge"
-
-external fn erl_delete(k, Map(k, v)) -> Map(k, v)
- = "maps" "remove"
+pub external fn merge(into: Map(k, v), merge: Map(k, v)) -> Map(k, v) =
+ "maps" "merge"
+external fn erl_delete(k, Map(k, v)) -> Map(k, v) =
+ "maps" "remove"
/// Create a new map from a given map with all the same entries except for the
/// one with a given key, if it exists.
@@ -253,9 +252,7 @@ pub fn delete(from map: Map(k, v), delete key: k) -> Map(k, v) {
/// from_list([])
///
pub fn drop(from map: Map(k, v), drop disallowed_keys: List(k)) -> Map(k, v) {
- list.fold(disallowed_keys, map, fn(key, acc) {
- delete(acc, key)
- })
+ list.fold(disallowed_keys, map, fn(key, acc) { delete(acc, key) })
}
/// Create a new map with one entry updated using a given function.
@@ -284,7 +281,10 @@ pub fn update(
update key: k,
with fun: fn(Option(v)) -> v,
) -> Map(k, v) {
- map |> get(_, key) |> fun |> insert(map, key, _)
+ map
+ |> get(key)
+ |> fun
+ |> insert(map, key, _)
}
fn do_fold(
@@ -294,7 +294,7 @@ fn do_fold(
) -> acc {
case list {
[] -> initial
- [tuple(k, v) | tail] -> do_fold(tail, fun(k, v, initial), fun)
+ [tuple(k, v), ..tail] -> do_fold(tail, fun(k, v, initial), fun)
}
}
@@ -320,5 +320,7 @@ pub fn fold(
from initial: acc,
with fun: fn(k, v, acc) -> acc,
) -> acc {
- map |> to_list |> do_fold(_, initial, fun)
+ map
+ |> to_list
+ |> do_fold(initial, fun)
}
diff --git a/src/gleam/result.gleam b/src/gleam/result.gleam
index b002f8e..7dd2076 100644
--- a/src/gleam/result.gleam
+++ b/src/gleam/result.gleam
@@ -71,10 +71,7 @@ pub fn is_error(result: Result(a, e)) -> Bool {
/// > map(over: Error(1), with: fn(x) { x + 1 })
/// Error(1)
///
-pub fn map(
- over result: Result(a, e),
- with fun: fn(a) -> b,
-) -> Result(b, e) {
+pub fn map(over result: Result(a, e), with fun: fn(a) -> b) -> Result(b, e) {
case result {
Ok(x) -> Ok(fun(x))
Error(e) -> Error(e)
diff --git a/src/gleam/should.gleam b/src/gleam/should.gleam
index b0a1dc5..de07f10 100644
--- a/src/gleam/should.gleam
+++ b/src/gleam/should.gleam
@@ -6,20 +6,25 @@
// TODO: Move this module into another package so it can be used as a
// dep only in test.
+pub external type Expectation
-pub external type Expectation;
+pub external fn equal(a, a) -> Expectation =
+ "gleam_stdlib" "should_equal"
-pub external fn equal(a, a) -> Expectation = "gleam_stdlib" "should_equal";
+pub external fn not_equal(a, a) -> Expectation =
+ "gleam_stdlib" "should_not_equal"
-pub external fn not_equal(a, a) -> Expectation = "gleam_stdlib" "should_not_equal";
+pub external fn be_true(Bool) -> Expectation =
+ "gleam_stdlib" "should_be_true"
-pub external fn be_true(Bool) -> Expectation = "gleam_stdlib" "should_be_true";
+pub external fn be_false(Bool) -> Expectation =
+ "gleam_stdlib" "should_be_false"
-pub external fn be_false(Bool) -> Expectation = "gleam_stdlib" "should_be_false";
+pub external fn be_ok(Result(a, b)) -> Expectation =
+ "gleam_stdlib" "should_be_ok"
-pub external fn be_ok(Result(a, b)) -> Expectation = "gleam_stdlib" "should_be_ok";
-
-pub external fn be_error(Result(a, b)) -> Expectation = "gleam_stdlib" "should_be_error";
+pub external fn be_error(Result(a, b)) -> Expectation =
+ "gleam_stdlib" "should_be_error"
pub fn fail() -> Expectation {
be_true(False)
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam
index de6f58a..8c270bc 100644
--- a/src/gleam/string.gleam
+++ b/src/gleam/string.gleam
@@ -39,9 +39,10 @@ pub fn is_empty(str: String) -> Bool {
///
/// > length("")
/// 0
-///
-pub external fn length(String) -> Int = "string" "length"
+pub external fn length(String) -> Int =
+ "string" "length"
+///
/// Reverse a string.
///
/// This function has to iterate across the whole string so it runs in linear
@@ -51,7 +52,6 @@ pub external fn length(String) -> Int = "string" "length"
///
/// > reverse("stressed")
/// "desserts"
-///
pub fn reverse(string: String) -> String {
string
|> iodata.new
@@ -59,6 +59,7 @@ pub fn reverse(string: String) -> String {
|> iodata.to_string
}
+///
/// Create a new string by replacing all occurrences of a given substring.
///
/// ## Examples
@@ -68,7 +69,6 @@ pub fn reverse(string: String) -> String {
///
/// > replace("a,b,c,d,e", each: ",", with: "/")
/// "a/b/c/d/e"
-///
pub fn replace(
in string: String,
each pattern: String,
@@ -76,10 +76,11 @@ pub fn replace(
) -> String {
string
|> iodata.new
- |> iodata.replace(_, each: pattern, with: substitute)
+ |> iodata.replace(each: pattern, with: substitute)
|> iodata.to_string
}
+///
/// Create a new string with all the graphemes in the input string converted to
/// lowercase.
///
@@ -89,9 +90,10 @@ pub fn replace(
///
/// > lowercase("X-FILES")
/// "x-files"
-///
-pub external fn lowercase(String) -> String = "string" "lowercase"
+pub external fn lowercase(String) -> String =
+ "string" "lowercase"
+///
/// Create a new string with all the graphemes in the input string converted to
/// uppercase.
///
@@ -101,9 +103,10 @@ pub external fn lowercase(String) -> String = "string" "lowercase"
///
/// > uppercase("skinner")
/// "SKINNER"
-///
-pub external fn uppercase(String) -> String = "string" "uppercase"
+pub external fn uppercase(String) -> String =
+ "string" "uppercase"
+///
/// Compares two strings to see which is "larger" by comparing their graphemes.
///
/// This does not compare the size or length of the given strings.
@@ -115,7 +118,6 @@ pub external fn uppercase(String) -> String = "string" "uppercase"
///
/// > compare("A", "B")
/// order.Gt
-///
pub external fn compare(String, String) -> order.Order =
"gleam_stdlib" "compare_strings"
@@ -135,17 +137,15 @@ pub external fn compare(String, String) -> order.Order =
//
//
// pub fn slice(out_of string: String, from start: Int, end: Int) -> String {}
-
// TODO
-/// Drop *n* Graphemes from the left side of a
-///
-/// ## Examples
-/// > drop_left(from: "The Lone Gunmen", up_to: 2)
-/// "e Lone Gunmen"
-///
-///
+// Drop *n* Graphemes from the left side of a
+//
+// ## Examples
+// > drop_left(from: "The Lone Gunmen", up_to: 2)
+// "e Lone Gunmen"
+//
+//
// pub fn drop_left(from string: String, up_to num_graphemes: Int) -> String {}
-
// TODO
// Drop *n* Graphemes from the right side of a
//
@@ -155,8 +155,7 @@ pub external fn compare(String, String) -> order.Order =
//
//
// pub fn drop_right(from string: String, up_to num_graphemes: Int) -> String {}
-
-
+///
/// Check if the first string contains the second.
///
/// ## Examples
@@ -169,12 +168,12 @@ pub external fn compare(String, String) -> order.Order =
///
/// > contains(does: "theory", contain: "THE")
/// False
-///
external fn erl_contains(String, String) -> Bool =
"gleam_stdlib" "string_contains"
+///
pub fn contains(does haystack: String, contain needle: String) -> Bool {
- erl_contains(haystack, needle)
+ erl_contains(haystack, needle)
}
// TODO
@@ -187,7 +186,6 @@ pub fn contains(does haystack: String, contain needle: String) -> Bool {
//
//
// pub fn starts_with(does string: String, start_with prefix: String) -> String {}
-
// TODO
// TODO: Not sure about the name and labels here
// See if the second string ends with the first one.
@@ -198,22 +196,20 @@ pub fn contains(does haystack: String, contain needle: String) -> Bool {
//
//
// pub fn ends_with(does string: String, end_with suffix: String) -> String {}
-
/// Create a list of strings by splitting a given string on a given substring.
///
/// ## Examples
///
/// > split("home/gleam/desktop/", on: "/")
/// ["home","gleam","desktop", ""]
-///
pub fn split(x: String, on substring: String) -> List(String) {
x
|> iodata.new
- |> iodata.split(_, on: substring)
- |> list.map(_, with: iodata.to_string)
+ |> iodata.split(on: substring)
+ |> list.map(with: iodata.to_string)
}
-
+///
/// Create a new string by joining two strings together.
///
/// This function copies both strings and runs in linear time. If you find
@@ -224,14 +220,14 @@ pub fn split(x: String, on substring: String) -> List(String) {
///
/// > append(to: "butter", suffix: "fly")
/// "butterfly"
-///
pub fn append(to first: String, suffix second: String) -> String {
first
|> iodata.new
- |> iodata.append(_, second)
+ |> iodata.append(second)
|> iodata.to_string
}
+///
/// Create a new string by joining many strings together.
///
/// This function copies both strings and runs in linear time. If you find
@@ -242,17 +238,17 @@ pub fn append(to first: String, suffix second: String) -> String {
///
/// > concat(["never", "the", "less"])
/// "nevertheless"
-///
pub fn concat(strings: List(String)) -> String {
strings
|> iodata.from_strings
|> iodata.to_string
}
+///
fn repeat_help(chunk: String, result: List(String), repeats: Int) -> String {
case repeats <= 0 {
- True -> concat(result)
- False -> repeat_help(chunk, [chunk | result], repeats - 1)
+ True -> concat(result)
+ False -> repeat_help(chunk, [chunk, ..result], repeats - 1)
}
}
@@ -263,11 +259,11 @@ fn repeat_help(chunk: String, result: List(String), repeats: Int) -> String {
/// ## Examples
/// > repeat("ha", times: 3)
/// "hahaha"
-///
pub fn repeat(string: String, times times: Int) -> String {
repeat_help(string, [], times)
}
+///
/// Join many strings together with a given separator.
///
/// This function runs in linear time.
@@ -276,14 +272,13 @@ pub fn repeat(string: String, times times: Int) -> String {
///
/// > join(["home","evan","Desktop"], with: "/")
/// "home/evan/Desktop"
-///
pub fn join(strings: List(String), with separator: String) -> String {
strings
- |> list.intersperse(_, with: separator)
+ |> list.intersperse(with: separator)
|> iodata.from_strings
|> iodata.to_string
}
-
+///
// TODO
// Pad a string on the left until it has at least given number of Graphemes.
//
@@ -299,7 +294,6 @@ pub fn join(strings: List(String), with separator: String) -> String {
//
//
// pub fn pad_left(string: String, to size: Int, with: String) {}
-
// TODO
// Pad a string on the right until it has a given length.
//
@@ -315,7 +309,6 @@ pub fn join(strings: List(String), with separator: String) -> String {
//
//
// pub fn pad_right(string: String, to size: Int, with: String) {}
-
// TODO
// Get rid of whitespace on both sides of a String.
//
@@ -325,7 +318,6 @@ pub fn join(strings: List(String), with separator: String) -> String {
//
//
// pub fn trim(string: String) -> String {}
-
// TODO
// Get rid of whitespace on the left of a String.
//
@@ -335,7 +327,6 @@ pub fn join(strings: List(String), with separator: String) -> String {
//
//
// pub fn trim_left(string: String) -> String {}
-
// TODO
// Get rid of whitespace on the right of a String.
//
@@ -345,7 +336,6 @@ pub fn join(strings: List(String), with separator: String) -> String {
//
//
// pub fn trim_right(string: String) -> String {}
-
// TODO
// /// Convert a string to a list of Graphemes.
// ///
@@ -354,7 +344,6 @@ pub fn join(strings: List(String), with separator: String) -> String {
//
// ///
// pub fn to_graphemes(string: String) -> List(String) {}
-
// TODO
// Split a non-empty string into its head and tail. This lets you
// pattern match on strings exactly as you would with lists.
diff --git a/test/gleam/atom_test.gleam b/test/gleam/atom_test.gleam
index da0699a..29a5b41 100644
--- a/test/gleam/atom_test.gleam
+++ b/test/gleam/atom_test.gleam
@@ -12,34 +12,36 @@ pub fn from_string_test() {
"this is not an atom we have seen before"
|> atom.from_string
- |> should.equal(_, Error(atom.AtomNotLoaded))
+ |> should.equal(Error(atom.AtomNotLoaded))
}
pub fn create_from_string_test() {
"ok"
|> atom.create_from_string
|> Ok
- |> should.equal(_, atom.from_string("ok"))
+ |> should.equal(atom.from_string("ok"))
"expect"
|> atom.create_from_string
|> Ok
- |> should.equal(_, atom.from_string("expect"))
+ |> should.equal(atom.from_string("expect"))
"this is another atom we have not seen before"
|> atom.create_from_string
|> Ok
- |> should.equal(_, atom.from_string("this is another atom we have not seen before"))
+ |> should.equal(
+ atom.from_string("this is another atom we have not seen before"),
+ )
}
pub fn to_string_test() {
"ok"
|> atom.create_from_string
|> atom.to_string
- |> should.equal(_, "ok")
+ |> should.equal("ok")
"expect"
|> atom.create_from_string
|> atom.to_string
- |> should.equal(_, "expect")
+ |> should.equal("expect")
}
diff --git a/test/gleam/bool_test.gleam b/test/gleam/bool_test.gleam
index 4e2b8e0..a05327f 100644
--- a/test/gleam/bool_test.gleam
+++ b/test/gleam/bool_test.gleam
@@ -12,50 +12,50 @@ pub fn negate_test() {
pub fn compare_test() {
bool.compare(True, True)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
bool.compare(True, False)
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
bool.compare(False, False)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
bool.compare(False, True)
- |> should.equal(_, order.Lt)
+ |> should.equal(order.Lt)
}
pub fn max_test() {
bool.max(True, True)
- |> should.equal(_, True)
+ |> should.equal(True)
bool.max(True, False)
- |> should.equal(_, True)
+ |> should.equal(True)
bool.max(False, False)
- |> should.equal(_, False)
+ |> should.equal(False)
bool.max(False, True)
- |> should.equal(_, True)
+ |> should.equal(True)
}
pub fn min_test() {
bool.min(True, True)
- |> should.equal(_, True)
+ |> should.equal(True)
bool.min(True, False)
- |> should.equal(_, False)
+ |> should.equal(False)
bool.min(False, False)
- |> should.equal(_, False)
+ |> should.equal(False)
bool.min(False, True)
- |> should.equal(_, False)
+ |> should.equal(False)
}
pub fn to_int_test() {
bool.to_int(True)
- |> should.equal(_, 1)
+ |> should.equal(1)
bool.to_int(False)
- |> should.equal(_, 0)
+ |> should.equal(0)
}
diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam
index 2a777c7..4f74556 100644
--- a/test/gleam/dynamic_test.gleam
+++ b/test/gleam/dynamic_test.gleam
@@ -9,66 +9,66 @@ pub fn string_test() {
""
|> dynamic.from
|> dynamic.string
- |> should.equal(_, Ok(""))
+ |> should.equal(Ok(""))
"Hello"
|> dynamic.from
|> dynamic.string
- |> should.equal(_, Ok("Hello"))
+ |> should.equal(Ok("Hello"))
1
|> dynamic.from
|> dynamic.string
- |> should.equal(_, Error("Expected a string, got an int"))
+ |> should.equal(Error("Expected a string, got an int"))
[]
|> dynamic.from
|> dynamic.string
- |> should.equal(_, Error("Expected a string, got a list"))
+ |> should.equal(Error("Expected a string, got a list"))
}
pub fn int_test() {
1
|> dynamic.from
|> dynamic.int
- |> should.equal(_, Ok(1))
+ |> should.equal(Ok(1))
2
|> dynamic.from
|> dynamic.int
- |> should.equal(_, Ok(2))
+ |> should.equal(Ok(2))
1.0
|> dynamic.from
|> dynamic.int
- |> should.equal(_, Error("Expected an int, got a float"))
+ |> should.equal(Error("Expected an int, got a float"))
[]
|> dynamic.from
|> dynamic.int
- |> should.equal(_, Error("Expected an int, got a list"))
+ |> should.equal(Error("Expected an int, got a list"))
}
pub fn float_test() {
1.0
|> dynamic.from
|> dynamic.float
- |> should.equal(_, Ok(1.0))
+ |> should.equal(Ok(1.0))
2.2
|> dynamic.from
|> dynamic.float
- |> should.equal(_, Ok(2.2))
+ |> should.equal(Ok(2.2))
1
|> dynamic.from
|> dynamic.float
- |> should.equal(_, Error("Expected a float, got an int"))
+ |> should.equal(Error("Expected a float, got an int"))
[]
|> dynamic.from
|> dynamic.float
- |> should.equal(_, Error("Expected a float, got a list"))
+ |> should.equal(Error("Expected a float, got a list"))
}
pub fn thunk_test() {
@@ -80,8 +80,8 @@ pub fn thunk_test() {
fn() { 1 }
|> dynamic.from
|> dynamic.thunk
- |> result.map(_, fn(f) { f() })
- |> should.equal(_, Ok(dynamic.from(1)))
+ |> result.map(fn(f) { f() })
+ |> should.equal(Ok(dynamic.from(1)))
fn(x) { x }
|> dynamic.from
@@ -103,87 +103,87 @@ pub fn bool_test() {
True
|> dynamic.from
|> dynamic.bool
- |> should.equal(_, Ok(True))
+ |> should.equal(Ok(True))
False
|> dynamic.from
|> dynamic.bool
- |> should.equal(_, Ok(False))
+ |> should.equal(Ok(False))
1
|> dynamic.from
|> dynamic.bool
- |> should.equal(_, Error("Expected a bool, got an int"))
+ |> should.equal(Error("Expected a bool, got an int"))
[]
|> dynamic.from
|> dynamic.bool
- |> should.equal(_, Error("Expected a bool, got a list"))
+ |> should.equal(Error("Expected a bool, got a list"))
}
pub fn atom_test() {
""
- |> atom.create_from_string
- |> dynamic.from
- |> dynamic.atom
- |> should.equal(_, Ok(atom.create_from_string("")))
+ |> atom.create_from_string
+ |> dynamic.from
+ |> dynamic.atom
+ |> should.equal(Ok(atom.create_from_string("")))
"ok"
- |> atom.create_from_string
- |> dynamic.from
- |> dynamic.atom
- |> should.equal(_, Ok(atom.create_from_string("ok")))
+ |> atom.create_from_string
+ |> dynamic.from
+ |> dynamic.atom
+ |> should.equal(Ok(atom.create_from_string("ok")))
1
- |> dynamic.from
- |> dynamic.atom
- |> should.be_error
+ |> dynamic.from
+ |> dynamic.atom
+ |> should.be_error
[]
- |> dynamic.from
- |> dynamic.atom
- |> should.be_error
+ |> dynamic.from
+ |> dynamic.atom
+ |> should.be_error
}
pub fn list_test() {
[]
|> dynamic.from
- |> dynamic.list(_, dynamic.string)
- |> should.equal(_, Ok([]))
+ |> dynamic.list(dynamic.string)
+ |> should.equal(Ok([]))
[]
|> dynamic.from
- |> dynamic.list(_, dynamic.int)
- |> should.equal(_, Ok([]))
+ |> dynamic.list(dynamic.int)
+ |> should.equal(Ok([]))
[1, 2, 3]
|> dynamic.from
- |> dynamic.list(_, dynamic.int)
- |> should.equal(_, Ok([1, 2, 3]))
+ |> dynamic.list(dynamic.int)
+ |> should.equal(Ok([1, 2, 3]))
[[1], [2], [3]]
|> dynamic.from
- |> dynamic.list(_, dynamic.list(_, dynamic.int))
- |> should.equal(_, Ok([[1], [2], [3]]))
+ |> dynamic.list(dynamic.list(_, dynamic.int))
+ |> should.equal(Ok([[1], [2], [3]]))
1
|> dynamic.from
- |> dynamic.list(_, dynamic.string)
+ |> dynamic.list(dynamic.string)
|> should.be_error
1.0
|> dynamic.from
- |> dynamic.list(_, dynamic.int)
+ |> dynamic.list(dynamic.int)
|> should.be_error
[""]
|> dynamic.from
- |> dynamic.list(_, dynamic.int)
+ |> dynamic.list(dynamic.int)
|> should.be_error
[dynamic.from(1), dynamic.from("not an int")]
|> dynamic.from
- |> dynamic.list(_, dynamic.int)
+ |> dynamic.list(dynamic.int)
|> should.be_error
}
@@ -192,31 +192,31 @@ pub fn field_test() {
let Ok(error_atom) = atom.from_string("error")
map.new()
- |> map.insert(_, ok_atom, 1)
+ |> map.insert(ok_atom, 1)
|> dynamic.from
- |> dynamic.field(_, ok_atom)
- |> should.equal(_, Ok(dynamic.from(1)))
+ |> dynamic.field(ok_atom)
+ |> should.equal(Ok(dynamic.from(1)))
map.new()
- |> map.insert(_, ok_atom, 3)
- |> map.insert(_, error_atom, 1)
+ |> map.insert(ok_atom, 3)
+ |> map.insert(error_atom, 1)
|> dynamic.from
- |> dynamic.field(_, ok_atom)
- |> should.equal(_, Ok(dynamic.from(3)))
+ |> dynamic.field(ok_atom)
+ |> should.equal(Ok(dynamic.from(3)))
map.new()
|> dynamic.from
- |> dynamic.field(_, ok_atom)
+ |> dynamic.field(ok_atom)
|> should.be_error
1
|> dynamic.from
- |> dynamic.field(_, ok_atom)
+ |> dynamic.field(ok_atom)
|> should.be_error
[]
|> dynamic.from
- |> dynamic.field(_, [])
+ |> dynamic.field([])
|> should.be_error
}
@@ -226,32 +226,32 @@ pub fn element_test() {
ok_one_tuple
|> dynamic.from
- |> dynamic.element(_, 0)
- |> should.equal(_, Ok(dynamic.from(ok_atom)))
+ |> dynamic.element(0)
+ |> should.equal(Ok(dynamic.from(ok_atom)))
ok_one_tuple
|> dynamic.from
- |> dynamic.element(_, 1)
- |> should.equal(_, Ok(dynamic.from(1)))
+ |> dynamic.element(1)
+ |> should.equal(Ok(dynamic.from(1)))
ok_one_tuple
|> dynamic.from
- |> dynamic.element(_, 2)
+ |> dynamic.element(2)
|> should.be_error
ok_one_tuple
|> dynamic.from
- |> dynamic.element(_, -1)
+ |> dynamic.element(-1)
|> should.be_error
1
|> dynamic.from
- |> dynamic.element(_, 0)
+ |> dynamic.element(0)
|> should.be_error
map.new()
- |> map.insert(_, 1, ok_atom)
+ |> map.insert(1, ok_atom)
|> dynamic.from
- |> dynamic.element(_, 0)
+ |> dynamic.element(0)
|> should.be_error
}
diff --git a/test/gleam/float_test.gleam b/test/gleam/float_test.gleam
index 038801a..d8ed02e 100644
--- a/test/gleam/float_test.gleam
+++ b/test/gleam/float_test.gleam
@@ -5,181 +5,181 @@ import gleam/order
pub fn parse_test() {
"1.23"
|> float.parse
- |> should.equal(_, Ok(1.23))
+ |> should.equal(Ok(1.23))
"5.0"
|> float.parse
- |> should.equal(_, Ok(5.0))
+ |> should.equal(Ok(5.0))
"0.123456789"
|> float.parse
- |> should.equal(_, Ok(0.123456789))
+ |> should.equal(Ok(0.123456789))
""
|> float.parse
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
"what"
|> float.parse
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
"1"
|> float.parse
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
}
pub fn to_string_test() {
123.0
|> float.to_string
- |> should.equal(_, "123.0")
+ |> should.equal("123.0")
-8.1
|> float.to_string
- |> should.equal(_, "-8.1")
+ |> should.equal("-8.1")
}
pub fn compare_test() {
float.compare(0., 0.)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
float.compare(0.1, 0.1)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
float.compare(0., 0.1)
- |> should.equal(_, order.Lt)
+ |> should.equal(order.Lt)
float.compare(-2., -1.9)
- |> should.equal(_, order.Lt)
+ |> should.equal(order.Lt)
float.compare(2., 1.9)
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
float.compare(-1.9, -2.)
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
}
pub fn ceiling_test() {
8.1
|> float.ceiling
- |> should.equal(_, 9.0)
+ |> should.equal(9.0)
-8.1
|> float.ceiling
- |> should.equal(_, -8.0)
+ |> should.equal(-8.0)
-8.0
|> float.ceiling
- |> should.equal(_, -8.0)
+ |> should.equal(-8.0)
}
pub fn floor_test() {
8.1
|> float.floor
- |> should.equal(_, 8.0)
+ |> should.equal(8.0)
-8.1
|> float.floor
- |> should.equal(_, -9.0)
+ |> should.equal(-9.0)
-8.0
|> float.floor
- |> should.equal(_, -8.0)
+ |> should.equal(-8.0)
}
pub fn round_test() {
8.1
|> float.round
- |> should.equal(_, 8)
+ |> should.equal(8)
8.4
|> float.round
- |> should.equal(_, 8)
+ |> should.equal(8)
8.499
|> float.round
- |> should.equal(_, 8)
+ |> should.equal(8)
8.5
|> float.round
- |> should.equal(_, 9)
+ |> should.equal(9)
-8.1
|> float.round
- |> should.equal(_, -8)
+ |> should.equal(-8)
-7.5
|> float.round
- |> should.equal(_, -8)
+ |> should.equal(-8)
}
pub fn truncate_test() {
8.1
|> float.truncate
- |> should.equal(_, 8)
+ |> should.equal(8)
8.4
|> float.truncate
- |> should.equal(_, 8)
+ |> should.equal(8)
8.499
|> float.truncate
- |> should.equal(_, 8)
+ |> should.equal(8)
8.5
|> float.truncate
- |> should.equal(_, 8)
+ |> should.equal(8)
-8.1
|> float.truncate
- |> should.equal(_, -8)
+ |> should.equal(-8)
-7.5
|> float.truncate
- |> should.equal(_, -7)
+ |> should.equal(-7)
}
pub fn min_test() {
float.min(0., 0.)
- |> should.equal(_, 0.)
+ |> should.equal(0.)
float.min(0.3, 1.5)
- |> should.equal(_, 0.3)
+ |> should.equal(0.3)
float.min(1., 0.)
- |> should.equal(_, 0.)
+ |> should.equal(0.)
float.min(-1.7, 2.5)
- |> should.equal(_, -1.7)
+ |> should.equal(-1.7)
float.min(-2.2, -2.2)
- |> should.equal(_, -2.2)
+ |> should.equal(-2.2)
float.min(-1., -1.)
- |> should.equal(_, -1.)
+ |> should.equal(-1.)
float.min(-1.1, -1.)
- |> should.equal(_, -1.1)
+ |> should.equal(-1.1)
}
pub fn max_test() {
float.max(0., 0.)
- |> should.equal(_, 0.)
+ |> should.equal(0.)
float.max(0.3, 1.5)
- |> should.equal(_, 1.5)
+ |> should.equal(1.5)
float.max(1., 0.)
- |> should.equal(_, 1.)
+ |> should.equal(1.)
float.max(-1.7, 2.5)
- |> should.equal(_, 2.5)
+ |> should.equal(2.5)
float.max(-2.2, -2.2)
- |> should.equal(_, -2.2)
+ |> should.equal(-2.2)
float.max(-1., -1.)
- |> should.equal(_, -1.)
+ |> should.equal(-1.)
float.max(-1.1, -1.)
- |> should.equal(_, -1.)
+ |> should.equal(-1.)
}
diff --git a/test/gleam/function_test.gleam b/test/gleam/function_test.gleam
index ee4fc00..eb94581 100644
--- a/test/gleam/function_test.gleam
+++ b/test/gleam/function_test.gleam
@@ -13,56 +13,55 @@ pub fn compose_test() {
1
|> add_five
- |> should.equal(_, 6)
+ |> should.equal(6)
// Takes a list of ints and returns the head as a string (if there is one, or
// else "0" if there is not)
- let head_to_string =
- list.head
- |> function.compose(_, result.unwrap(_, 0))
- |> function.compose(_, int.to_string)
+ let head_to_string = list.head
+ |> function.compose(result.unwrap(_, 0))
+ |> function.compose(int.to_string)
[1]
|> head_to_string
- |> should.equal(_, "1")
+ |> should.equal("1")
[]
|> head_to_string
- |> should.equal(_, "0")
+ |> should.equal("0")
}
pub fn flip_test() {
let fun = fn(s: String, i: Int) {
s
|> string.append("String: '", _)
- |> string.append(_, "', Int: '")
- |> string.append(_, int.to_string(i))
- |> string.append(_, "'")
+ |> string.append("', Int: '")
+ |> string.append(int.to_string(i))
+ |> string.append("'")
}
let flipped_fun = function.flip(fun)
fun("Bob", 1)
- |> should.equal(_, "String: 'Bob', Int: '1'")
+ |> should.equal("String: 'Bob', Int: '1'")
flipped_fun(2, "Alice")
- |> should.equal(_, "String: 'Alice', Int: '2'")
+ |> should.equal("String: 'Alice', Int: '2'")
}
pub fn identity_test() {
1
|> function.identity
- |> should.equal(_, 1)
+ |> should.equal(1)
""
|> function.identity
- |> should.equal(_, "")
+ |> should.equal("")
[]
|> function.identity
- |> should.equal(_, [])
+ |> should.equal([])
tuple(1, 2.0)
|> function.identity
- |> should.equal(_, tuple(1, 2.0))
+ |> should.equal(tuple(1, 2.0))
}
diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam
index 27335d5..204e72c 100644
--- a/test/gleam/int_test.gleam
+++ b/test/gleam/int_test.gleam
@@ -5,111 +5,111 @@ import gleam/order
pub fn to_string() {
123
|> int.to_string
- |> should.equal(_, "123")
+ |> should.equal("123")
-123
|> int.to_string
- |> should.equal(_, "-123")
+ |> should.equal("-123")
123
|> int.to_string
- |> should.equal(_, "123")
+ |> should.equal("123")
}
pub fn parse() {
"123"
|> int.parse
- |> should.equal(_, Ok(123))
+ |> should.equal(Ok(123))
"-123"
|> int.parse
- |> should.equal(_, Ok(-123))
+ |> should.equal(Ok(-123))
"0123"
|> int.parse
- |> should.equal(_, Ok(123))
+ |> should.equal(Ok(123))
""
|> int.parse
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
"what"
|> int.parse
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
"1.23"
|> int.parse
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
}
pub fn to_base_string() {
100
- |> int.to_base_string(_, 16)
- |> should.equal(_, "64")
+ |> int.to_base_string(16)
+ |> should.equal("64")
-100
- |> int.to_base_string(_, 16)
- |> should.equal(_, "-64")
+ |> int.to_base_string(16)
+ |> should.equal("-64")
}
pub fn compare_test() {
int.compare(0, 0)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
int.compare(1, 1)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
int.compare(0, 1)
- |> should.equal(_, order.Lt)
+ |> should.equal(order.Lt)
int.compare(-2, -1)
- |> should.equal(_, order.Lt)
+ |> should.equal(order.Lt)
int.compare(2, 1)
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
int.compare(-1, -2)
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
}
pub fn min_test() {
int.min(0, 0)
- |> should.equal(_, 0)
+ |> should.equal(0)
int.min(0, 1)
- |> should.equal(_, 0)
+ |> should.equal(0)
int.min(1, 0)
- |> should.equal(_, 0)
+ |> should.equal(0)
int.min(-1, 2)
- |> should.equal(_, -1)
+ |> should.equal(-1)
int.min(2, -2)
- |> should.equal(_, -2)
+ |> should.equal(-2)
int.min(-1, -1)
- |> should.equal(_, -1)
+ |> should.equal(-1)
}
pub fn max_test() {
int.max(0, 0)
- |> should.equal(_, 0)
+ |> should.equal(0)
int.max(0, 1)
- |> should.equal(_, 1)
+ |> should.equal(1)
int.max(1, 0)
- |> should.equal(_, 1)
+ |> should.equal(1)
int.max(-1, 2)
- |> should.equal(_, 2)
+ |> should.equal(2)
int.max(2, -2)
- |> should.equal(_, 2)
+ |> should.equal(2)
int.max(-1, -1)
- |> should.equal(_, -1)
+ |> should.equal(-1)
}
pub fn is_even_test() {
diff --git a/test/gleam/iodata_test.gleam b/test/gleam/iodata_test.gleam
index e9922e4..bc4fe98 100644
--- a/test/gleam/iodata_test.gleam
+++ b/test/gleam/iodata_test.gleam
@@ -3,30 +3,32 @@ import gleam/iodata
pub fn iodata_test() {
let data = iodata.new("ello")
- |> iodata.append(_, ",")
- |> iodata.append(_, " world!")
- |> iodata.prepend(_, "H")
+ |> iodata.append(",")
+ |> iodata.append(" world!")
+ |> iodata.prepend("H")
data
|> iodata.to_string
- |> should.equal(_, "Hello, world!")
+ |> should.equal("Hello, world!")
data
|> iodata.byte_size
- |> should.equal(_, 13)
+ |> should.equal(13)
let data = iodata.new("ello")
- |> iodata.append_iodata(_, iodata.new(","))
- |> iodata.append_iodata(_, iodata.concat([iodata.new(" wo"), iodata.new("rld!")]))
- |> iodata.prepend_iodata(_, iodata.new("H"))
+ |> iodata.append_iodata(iodata.new(","))
+ |> iodata.append_iodata(
+ iodata.concat([iodata.new(" wo"), iodata.new("rld!")]),
+ )
+ |> iodata.prepend_iodata(iodata.new("H"))
data
|> iodata.to_string
- |> should.equal(_, "Hello, world!")
+ |> should.equal("Hello, world!")
data
|> iodata.byte_size
- |> should.equal(_, 13)
+ |> should.equal(13)
}
pub fn lowercase_test() {
@@ -34,7 +36,7 @@ pub fn lowercase_test() {
|> iodata.from_strings
|> iodata.lowercase
|> iodata.to_string
- |> should.equal(_, "gleamgleam")
+ |> should.equal("gleamgleam")
}
pub fn uppercase_test() {
@@ -42,32 +44,36 @@ pub fn uppercase_test() {
|> iodata.from_strings
|> iodata.uppercase
|> iodata.to_string
- |> should.equal(_, "GLEAMGLEAM")
+ |> should.equal("GLEAMGLEAM")
}
pub fn split_test() {
"Gleam,Erlang,Elixir"
|> iodata.new
- |> iodata.split(_, ",")
- |> should.equal(_, [iodata.new("Gleam"), iodata.new("Erlang"), iodata.new("Elixir")])
+ |> iodata.split(",")
+ |> should.equal(
+ [iodata.new("Gleam"), iodata.new("Erlang"), iodata.new("Elixir")],
+ )
["Gleam, Erl", "ang,Elixir"]
|> iodata.from_strings
- |> iodata.split(_, ", ")
- |> should.equal(_, [iodata.new("Gleam"), iodata.from_strings(["Erl", "ang,Elixir"])])
+ |> iodata.split(", ")
+ |> should.equal(
+ [iodata.new("Gleam"), iodata.from_strings(["Erl", "ang,Elixir"])],
+ )
}
pub fn is_equal_test() {
iodata.new("12")
- |> iodata.is_equal(_, iodata.from_strings(["1", "2"]))
+ |> iodata.is_equal(iodata.from_strings(["1", "2"]))
|> should.be_true
iodata.new("12")
- |> iodata.is_equal(_, iodata.new("12"))
+ |> iodata.is_equal(iodata.new("12"))
|> should.be_true
iodata.new("12")
- |> iodata.is_equal(_, iodata.new("2"))
+ |> iodata.is_equal(iodata.new("2"))
|> should.be_false
}
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index d54fe8f..1be4e43 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -7,79 +7,86 @@ import gleam/pair
pub fn length_test() {
list.length([])
- |> should.equal(_, 0)
+ |> should.equal(0)
list.length([1])
- |> should.equal(_, 1)
+ |> should.equal(1)
list.length([1, 1])
- |> should.equal(_, 2)
+ |> should.equal(2)
list.length([1, 1, 1])
- |> should.equal(_, 3)
+ |> should.equal(3)
}
pub fn reverse_test() {
- list.reverse([]) |> should.equal(_, [])
- list.reverse([1, 2, 3, 4, 5]) |> should.equal(_, [5, 4, 3, 2, 1])
+ list.reverse([])
+ |> should.equal([])
+ list.reverse([1, 2, 3, 4, 5])
+ |> should.equal([5, 4, 3, 2, 1])
}
pub fn is_empty_test() {
- list.is_empty([]) |> should.be_true
- list.is_empty([1]) |> should.be_false
+ list.is_empty([])
+ |> should.be_true
+ list.is_empty([1])
+ |> should.be_false
}
pub fn contains_test() {
- list.contains([0, 4, 5, 1], 1) |> should.be_true
- list.contains([0, 4, 5, 7], 1) |> should.be_false
- list.contains([], 1) |> should.be_false
+ list.contains([0, 4, 5, 1], 1)
+ |> should.be_true
+ list.contains([0, 4, 5, 7], 1)
+ |> should.be_false
+ list.contains([], 1)
+ |> should.be_false
}
pub fn head_test() {
list.head([0, 4, 5, 7])
- |> should.equal(_, Ok(0))
+ |> should.equal(Ok(0))
list.head([])
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
}
pub fn tail_test() {
list.tail([0, 4, 5, 7])
- |> should.equal(_, Ok([4, 5, 7]))
+ |> should.equal(Ok([4, 5, 7]))
list.tail([0])
- |> should.equal(_, Ok([]))
+ |> should.equal(Ok([]))
list.tail([])
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
}
pub fn filter_test() {
[]
- |> list.filter(_, fn(_) { True })
- |> should.equal(_, [])
+ |> list.filter(fn(_) { True })
+ |> should.equal([])
[0, 4, 5, 7, 3]
- |> list.filter(_, fn(_) { True })
- |> should.equal(_, [0, 4, 5, 7, 3])
+ |> list.filter(fn(_) { True })
+ |> should.equal([0, 4, 5, 7, 3])
[0, 4, 5, 7, 3]
- |> list.filter(_, fn(x) { x > 4 })
- |> should.equal(_, [5, 7])
+ |> list.filter(fn(x) { x > 4 })
+ |> should.equal([5, 7])
[0, 4, 5, 7, 3]
- |> list.filter(_, fn(x) { x < 4 })
- |> should.equal(_, [0, 3])
+ |> list.filter(fn(x) { x < 4 })
+ |> should.equal([0, 3])
}
pub fn map_test() {
[]
- |> list.map(_, fn(x) { x * 2 })
- |> should.equal(_, [])
+ |> list.map(fn(x) { x * 2 })
+ |> should.equal([])
[0, 4, 5, 7, 3]
- |> list.map(_, fn(x) { x * 2 })
- |> should.equal(_, [0, 8, 10, 14, 6])
+ |> list.map(fn(x) { x * 2 })
+ |> should.equal([0, 8, 10, 14, 6])
}
pub fn traverse_test() {
@@ -91,66 +98,67 @@ pub fn traverse_test() {
}
[5, 6, 5, 6]
- |> list.traverse(_, fun)
- |> should.equal(_, Ok([10, 12, 10, 12]))
+ |> list.traverse(fun)
+ |> should.equal(Ok([10, 12, 10, 12]))
[4, 6, 5, 7, 3]
- |> list.traverse(_, fun)
- |> should.equal(_, Error(7))
+ |> list.traverse(fun)
+ |> should.equal(Error(7))
}
pub fn drop_test() {
[]
- |> list.drop(_, 5)
- |> should.equal(_, [])
+ |> list.drop(5)
+ |> should.equal([])
[1, 2, 3, 4, 5, 6, 7, 8]
- |> list.drop(_, 5)
- |> should.equal(_, [6, 7, 8])
+ |> list.drop(5)
+ |> should.equal([6, 7, 8])
}
pub fn take_test() {
[]
- |> list.take(_, 5)
- |> should.equal(_, [])
+ |> list.take(5)
+ |> should.equal([])
[1, 2, 3, 4, 5, 6, 7, 8]
- |> list.take(_, 5)
- |> should.equal(_, [1, 2, 3, 4, 5])
+ |> list.take(5)
+ |> should.equal([1, 2, 3, 4, 5])
}
pub fn new_test() {
- list.new() |> should.equal(_, [])
+ list.new()
+ |> should.equal([])
}
pub fn append_test() {
list.append([1], [2, 3])
- |> should.equal(_, [1, 2, 3])
+ |> should.equal([1, 2, 3])
}
pub fn flatten_test() {
list.flatten([])
- |> should.equal(_, [])
+ |> should.equal([])
list.flatten([[]])
- |> should.equal(_, [])
+ |> should.equal([])
list.flatten([[], [], []])
- |> should.equal(_, [])
+ |> should.equal([])
list.flatten([[1, 2], [], [3, 4]])
- |> should.equal(_, [1, 2, 3, 4])
+ |> should.equal([1, 2, 3, 4])
}
pub fn fold_test() {
[1, 2, 3]
- |> list.fold(_, [], fn(x, acc) { [x | acc] })
- |> should.equal(_, [3, 2, 1])
+ |> list.fold([], fn(x, acc) { [x, ..acc] })
+ |> should.equal([3, 2, 1])
}
pub fn fold_right_test() {
[1, 2, 3]
- |> list.fold_right(_, from: [], with: fn(x, acc) { [x | acc] })
- |> should.equal(_, [1, 2, 3])
+ |> list.fold_right(from: [], with: fn(x, acc) { [x, ..acc] })
+ |> should.equal([1, 2, 3])
}
pub fn find_map_test() {
@@ -162,256 +170,247 @@ pub fn find_map_test() {
}
[1, 2, 3]
- |> list.find_map(_, with: f)
- |> should.equal(_, Ok(4))
+ |> list.find_map(with: f)
+ |> should.equal(Ok(4))
[1, 3, 2]
- |> list.find_map(_, with: f)
- |> should.equal(_, Ok(4))
+ |> list.find_map(with: f)
+ |> should.equal(Ok(4))
[1, 3]
- |> list.find_map(_, with: f)
- |> should.equal(_, Error(Nil))
+ |> list.find_map(with: f)
+ |> should.equal(Error(Nil))
}
pub fn find_test() {
- let is_two = fn(x) {
- x == 2
- }
+ let is_two = fn(x) { x == 2 }
[1, 2, 3]
- |> list.find(_, one_that: is_two)
- |> should.equal(_, Ok(2))
+ |> list.find(one_that: is_two)
+ |> should.equal(Ok(2))
[1, 3, 2]
- |> list.find(_, one_that: is_two)
- |> should.equal(_, Ok(2))
+ |> list.find(one_that: is_two)
+ |> should.equal(Ok(2))
[1, 3]
- |> list.find(_, one_that: is_two)
- |> should.equal(_, Error(Nil))
+ |> list.find(one_that: is_two)
+ |> should.equal(Error(Nil))
}
pub fn all_test() {
list.all([1, 2, 3, 4, 5], fn(x) { x > 0 })
- |> should.equal(_, True)
+ |> should.equal(True)
list.all([1, 2, 3, 4, 5], fn(x) { x < 0 })
- |> should.equal(_, False)
+ |> should.equal(False)
list.all([], fn(_) { False })
- |> should.equal(_, True)
+ |> should.equal(True)
}
pub fn any_test() {
list.any([1, 2, 3, 4, 5], fn(x) { x == 2 })
- |> should.equal(_, True)
+ |> should.equal(True)
list.any([1, 2, 3, 4, 5], fn(x) { x < 0 })
- |> should.equal(_, False)
+ |> should.equal(False)
list.any([], fn(_) { False })
- |> should.equal(_, False)
+ |> should.equal(False)
}
pub fn zip_test() {
list.zip([], [1, 2, 3])
- |> should.equal(_, [])
+ |> should.equal([])
list.zip([1, 2], [])
- |> should.equal(_, [])
+ |> should.equal([])
list.zip([1, 2, 3], [4, 5, 6])
- |> should.equal(_, [tuple(1, 4), tuple(2, 5), tuple(3, 6)])
+ |> should.equal([tuple(1, 4), tuple(2, 5), tuple(3, 6)])
list.zip([5, 6], [1, 2, 3])
- |> should.equal(_, [tuple(5, 1), tuple(6, 2)])
+ |> should.equal([tuple(5, 1), tuple(6, 2)])
list.zip([5, 6, 7], [1, 2])
- |> should.equal(_, [tuple(5, 1), tuple(6, 2)])
+ |> should.equal([tuple(5, 1), tuple(6, 2)])
}
pub fn strict_zip_test() {
list.strict_zip([], [1, 2, 3])
- |> should.equal(_, Error(list.LengthMismatch))
+ |> should.equal(Error(list.LengthMismatch))
list.strict_zip([1, 2], [])
- |> should.equal(_, Error(list.LengthMismatch))
+ |> should.equal(Error(list.LengthMismatch))
list.strict_zip([1, 2, 3], [4, 5, 6])
- |> should.equal(_, Ok([
- tuple(1, 4),
- tuple(2, 5),
- tuple(3, 6),
- ]))
+ |> should.equal(Ok([tuple(1, 4), tuple(2, 5), tuple(3, 6)]))
list.strict_zip([5, 6], [1, 2, 3])
- |> should.equal(_, Error(list.LengthMismatch))
+ |> should.equal(Error(list.LengthMismatch))
list.strict_zip([5, 6, 7], [1, 2])
- |> should.equal(_, Error(list.LengthMismatch))
+ |> should.equal(Error(list.LengthMismatch))
}
pub fn intersperse_test() {
list.intersperse([1, 2, 3], 4)
- |> should.equal(_, [1, 4, 2, 4, 3])
+ |> should.equal([1, 4, 2, 4, 3])
list.intersperse([], 2)
- |> should.equal(_, [])
+ |> should.equal([])
}
pub fn at_test() {
list.at([1, 2, 3], 2)
- |> should.equal(_, Ok(3))
+ |> should.equal(Ok(3))
list.at([1, 2, 3], 5)
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
list.at([], 0)
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
list.at([1, 2, 3, 4, 5, 6], -1)
- |> should.equal(_, Error(Nil))
+ |> should.equal(Error(Nil))
}
pub fn unique_test() {
list.unique([1, 1, 2, 3, 4, 4, 4, 5, 6])
- |> should.equal(_, [1, 2, 3, 4, 5, 6])
+ |> should.equal([1, 2, 3, 4, 5, 6])
list.unique([7, 1, 45, 6, 2, 47, 2, 7, 5])
- |> should.equal(_, [7, 1, 45, 6, 2, 47, 5])
+ |> should.equal([7, 1, 45, 6, 2, 47, 5])
list.unique([3, 4, 5])
- |> should.equal(_, [3, 4, 5])
+ |> should.equal([3, 4, 5])
list.unique([])
- |> should.equal(_, [])
+ |> should.equal([])
}
pub fn sort_test() {
[4, 3, 6, 5, 4]
- |> list.sort(_, int.compare)
- |> should.equal(_, [3, 4, 4, 5, 6])
+ |> list.sort(int.compare)
+ |> should.equal([3, 4, 4, 5, 6])
[4, 3, 6, 5, 4, 1]
- |> list.sort(_, int.compare)
- |> should.equal(_, [1, 3, 4, 4, 5, 6])
+ |> list.sort(int.compare)
+ |> should.equal([1, 3, 4, 4, 5, 6])
[4.1, 3.1, 6.1, 5.1, 4.1]
- |> list.sort(_, float.compare)
- |> should.equal(_, [3.1, 4.1, 4.1, 5.1, 6.1])
+ |> list.sort(float.compare)
+ |> should.equal([3.1, 4.1, 4.1, 5.1, 6.1])
[]
- |> list.sort(_, int.compare)
- |> should.equal(_, [])
+ |> list.sort(int.compare)
+ |> should.equal([])
}
pub fn index_map_test() {
list.index_map([3, 4, 5], fn(i, x) { tuple(i, x) })
- |> should.equal(_, [tuple(0, 3), tuple(1, 4), tuple(2, 5)])
+ |> should.equal([tuple(0, 3), tuple(1, 4), tuple(2, 5)])
- let f = fn(i, x) {
- string.append(x, int.to_string(i))
- }
+ let f = fn(i, x) { string.append(x, int.to_string(i)) }
list.index_map(["a", "b", "c"], f)
- |> should.equal(_, ["a0", "b1", "c2"])
+ |> should.equal(["a0", "b1", "c2"])
}
pub fn range_test() {
list.range(0, 0)
- |> should.equal(_, [])
+ |> should.equal([])
list.range(1, 1)
- |> should.equal(_, [])
+ |> should.equal([])
list.range(-1, -1)
- |> should.equal(_, [])
+ |> should.equal([])
list.range(0, 1)
- |> should.equal(_, [0])
+ |> should.equal([0])
list.range(0, 5)
- |> should.equal(_, [0, 1, 2, 3, 4])
+ |> should.equal([0, 1, 2, 3, 4])
list.range(1, -5)
- |> should.equal(_, [1, 0, -1, -2, -3, -4])
+ |> should.equal([1, 0, -1, -2, -3, -4])
}
pub fn repeat_test() {
list.repeat(1, -10)
- |> should.equal(_, [])
+ |> should.equal([])
list.repeat(1, 0)
- |> should.equal(_, [])
+ |> should.equal([])
list.repeat(2, 3)
- |> should.equal(_, [2, 2, 2])
+ |> should.equal([2, 2, 2])
list.repeat("x", 5)
- |> should.equal(_, ["x", "x", "x", "x", "x"])
+ |> should.equal(["x", "x", "x", "x", "x"])
}
pub fn split_test() {
[]
- |> list.split(_, 0)
- |> should.equal(_, tuple([], []))
+ |> list.split(0)
+ |> should.equal(tuple([], []))
[0, 1, 2, 3, 4]
- |> list.split(_, 0)
- |> should.equal(_, tuple([], [0, 1, 2, 3, 4]))
+ |> list.split(0)
+ |> should.equal(tuple([], [0, 1, 2, 3, 4]))
[0, 1, 2, 3, 4]
- |> list.split(_, -2)
- |> should.equal(_, tuple([], [0, 1, 2, 3, 4]))
+ |> list.split(-2)
+ |> should.equal(tuple([], [0, 1, 2, 3, 4]))
[0, 1, 2, 3, 4]
- |> list.split(_, 1)
- |> should.equal(_, tuple([0], [1, 2, 3, 4]))
+ |> list.split(1)
+ |> should.equal(tuple([0], [1, 2, 3, 4]))
[0, 1, 2, 3, 4]
- |> list.split(_, 3)
- |> should.equal(_, tuple([0, 1, 2], [3, 4]))
+ |> list.split(3)
+ |> should.equal(tuple([0, 1, 2], [3, 4]))
[0, 1, 2, 3, 4]
- |> list.split(_, 9)
- |> should.equal(_, tuple([0, 1, 2, 3, 4], []))
+ |> list.split(9)
+ |> should.equal(tuple([0, 1, 2, 3, 4], []))
}
pub fn split_while_test() {
[]
- |> list.split_while(_, fn(x) { x <= 5 })
- |> should.equal(_, tuple([], []))
+ |> list.split_while(fn(x) { x <= 5 })
+ |> should.equal(tuple([], []))
[1, 2, 3, 4, 5]
- |> list.split_while(_, fn(x) { x <= 5 })
- |> should.equal(_, tuple([1, 2, 3, 4, 5], []))
+ |> list.split_while(fn(x) { x <= 5 })
+ |> should.equal(tuple([1, 2, 3, 4, 5], []))
[1, 2, 3, 4, 5]
- |> list.split_while(_, fn(x) { x == 2 })
- |> should.equal(_, tuple([], [1, 2, 3, 4, 5]))
+ |> list.split_while(fn(x) { x == 2 })
+ |> should.equal(tuple([], [1, 2, 3, 4, 5]))
[1, 2, 3, 4, 5]
- |> list.split_while(_, fn(x) { x <= 3 })
- |> should.equal(_, tuple([1, 2, 3], [4, 5]))
+ |> list.split_while(fn(x) { x <= 3 })
+ |> should.equal(tuple([1, 2, 3], [4, 5]))
[1, 2, 3, 4, 5]
- |> list.split_while(_, fn(x) { x <= -3 })
- |> should.equal(_, tuple([], [1, 2, 3, 4, 5]))
+ |> list.split_while(fn(x) { x <= -3 })
+ |> should.equal(tuple([], [1, 2, 3, 4, 5]))
}
-
pub fn key_find_test() {
let proplist = [tuple(0, "1"), tuple(1, "2")]
proplist
- |> list.key_find(_, 0)
- |> should.equal(_, Ok("1"))
+ |> list.key_find(0)
+ |> should.equal(Ok("1"))
proplist
- |> list.key_find(_, 1)
- |> should.equal(_, Ok("2"))
+ |> list.key_find(1)
+ |> should.equal(Ok("2"))
proplist
- |> list.key_find(_, 2)
- |> should.equal(_, Error(Nil))
+ |> list.key_find(2)
+ |> should.equal(Error(Nil))
}
diff --git a/test/gleam/map_test.gleam b/test/gleam/map_test.gleam
index 58b7cb5..abd3daf 100644
--- a/test/gleam/map_test.gleam
+++ b/test/gleam/map_test.gleam
@@ -3,201 +3,134 @@ import gleam/should
import gleam/map
pub fn from_list_test() {
- [
- tuple(4, 0),
- tuple(1, 0),
- ]
+ [tuple(4, 0), tuple(1, 0)]
|> map.from_list
|> map.size
- |> should.equal(_, 2)
+ |> should.equal(2)
- [
- tuple(1, 0),
- tuple(1, 1),
- ]
+ [tuple(1, 0), tuple(1, 1)]
|> map.from_list
- |> should.equal(_, map.from_list([tuple(1, 1)]))
+ |> should.equal(map.from_list([tuple(1, 1)]))
}
pub fn has_key_test() {
[]
|> map.from_list
- |> map.has_key(_, 1)
+ |> map.has_key(1)
|> should.be_false
- [
- tuple(1, 0),
- ]
+ [tuple(1, 0)]
|> map.from_list
- |> map.has_key(_, 1)
+ |> map.has_key(1)
|> should.be_true
- [
- tuple(4, 0),
- tuple(1, 0),
- ]
+ [tuple(4, 0), tuple(1, 0)]
|> map.from_list
- |> map.has_key(_, 1)
+ |> map.has_key(1)
|> should.be_true
- [
- tuple(4, 0),
- tuple(1, 0),
- ]
+ [tuple(4, 0), tuple(1, 0)]
|> map.from_list
- |> map.has_key(_, 0)
+ |> map.has_key(0)
|> should.be_false
}
pub fn new_test() {
map.new()
|> map.size
- |> should.equal(_, 0)
+ |> should.equal(0)
map.new()
|> map.to_list
- |> should.equal(_, [])
+ |> should.equal([])
}
pub fn get_test() {
- let proplist = [
- tuple(4, 0),
- tuple(1, 1),
- ]
+ let proplist = [tuple(4, 0), tuple(1, 1)]
let m = map.from_list(proplist)
m
- |> map.get(_, 4)
- |> should.equal(_, Ok(0))
+ |> map.get(4)
+ |> should.equal(Ok(0))
m
- |> map.get(_, 1)
- |> should.equal(_, Ok(1))
+ |> map.get(1)
+ |> should.equal(Ok(1))
m
- |> map.get(_, 2)
- |> should.equal(_, Error(Nil))
+ |> map.get(2)
+ |> should.equal(Error(Nil))
}
pub fn insert_test() {
map.new()
- |> map.insert(_, "a", 0)
- |> map.insert(_, "b", 1)
- |> map.insert(_, "c", 2)
- |> should.equal(_, map.from_list([
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ]))
+ |> map.insert("a", 0)
+ |> map.insert("b", 1)
+ |> map.insert("c", 2)
+ |> should.equal(map.from_list([tuple("a", 0), tuple("b", 1), tuple("c", 2)]))
}
pub fn map_values_test() {
- [
- tuple(1, 0),
- tuple(2, 1),
- tuple(3, 2),
- ]
+ [tuple(1, 0), tuple(2, 1), tuple(3, 2)]
|> map.from_list
- |> map.map_values(_, fn(k, v) { k + v })
- |> should.equal(_, map.from_list([
- tuple(1, 1),
- tuple(2, 3),
- tuple(3, 5),
- ]))
+ |> map.map_values(fn(k, v) { k + v })
+ |> should.equal(map.from_list([tuple(1, 1), tuple(2, 3), tuple(3, 5)]))
}
pub fn keys_test() {
- [
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ]
+ [tuple("a", 0), tuple("b", 1), tuple("c", 2)]
|> map.from_list
|> map.keys
- |> should.equal(_, ["a", "b", "c"])
+ |> should.equal(["a", "b", "c"])
}
pub fn values_test() {
- [
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ]
+ [tuple("a", 0), tuple("b", 1), tuple("c", 2)]
|> map.from_list
|> map.values
- |> should.equal(_, [0, 1, 2])
+ |> should.equal([0, 1, 2])
}
pub fn take_test() {
- [
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ]
+ [tuple("a", 0), tuple("b", 1), tuple("c", 2)]
|> map.from_list
- |> map.take(_, ["a", "b", "d"])
- |> should.equal(_, map.from_list([tuple("a", 0), tuple("b", 1)]))
+ |> map.take(["a", "b", "d"])
+ |> should.equal(map.from_list([tuple("a", 0), tuple("b", 1)]))
}
pub fn drop_test() {
- [
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ]
+ [tuple("a", 0), tuple("b", 1), tuple("c", 2)]
|> map.from_list
- |> map.drop(_, ["a", "b", "d"])
- |> should.equal(_, map.from_list([tuple("c", 2)]))
+ |> map.drop(["a", "b", "d"])
+ |> should.equal(map.from_list([tuple("c", 2)]))
}
pub fn merge_test() {
- let a = map.from_list([
- tuple("a", 2),
- tuple("c", 4),
- tuple("d", 3),
- ])
-
- let b = map.from_list([
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ])
+ let a = map.from_list([tuple("a", 2), tuple("c", 4), tuple("d", 3)])
+
+ let b = map.from_list([tuple("a", 0), tuple("b", 1), tuple("c", 2)])
map.merge(a, b)
- |> should.equal(_, map.from_list([
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- tuple("d", 3),
- ]))
+ |> should.equal(
+ map.from_list([tuple("a", 0), tuple("b", 1), tuple("c", 2), tuple("d", 3)]),
+ )
map.merge(b, a)
- |> should.equal(_, map.from_list([
- tuple("a", 2),
- tuple("b", 1),
- tuple("c", 4),
- tuple("d", 3),
- ]))
+ |> should.equal(
+ map.from_list([tuple("a", 2), tuple("b", 1), tuple("c", 4), tuple("d", 3)]),
+ )
}
pub fn delete_test() {
- [
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ]
+ [tuple("a", 0), tuple("b", 1), tuple("c", 2)]
|> map.from_list
- |> map.delete(_, "a")
- |> map.delete(_, "d")
- |> should.equal(_, map.from_list([tuple("b", 1), tuple("c", 2)]))
+ |> map.delete("a")
+ |> map.delete("d")
+ |> should.equal(map.from_list([tuple("b", 1), tuple("c", 2)]))
}
pub fn update_test() {
- let dict = map.from_list([
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- ])
+ let dict = map.from_list([tuple("a", 0), tuple("b", 1), tuple("c", 2)])
let inc_or_zero = fn(x) {
case x {
@@ -207,56 +140,38 @@ pub fn update_test() {
}
dict
- |> map.update(_, "a", inc_or_zero)
- |> should.equal(_, map.from_list([
- tuple("a", 1),
- tuple("b", 1),
- tuple("c", 2),
- ]))
+ |> map.update("a", inc_or_zero)
+ |> should.equal(map.from_list([tuple("a", 1), tuple("b", 1), tuple("c", 2)]))
dict
- |> map.update(_, "b", inc_or_zero)
- |> should.equal(_, map.from_list([
- tuple("a", 0),
- tuple("b", 2),
- tuple("c", 2),
- ]))
+ |> map.update("b", inc_or_zero)
+ |> should.equal(map.from_list([tuple("a", 0), tuple("b", 2), tuple("c", 2)]))
dict
- |> map.update(_, "z", inc_or_zero)
- |> should.equal(_, map.from_list([
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- tuple("z", 0),
- ]))
+ |> map.update("z", inc_or_zero)
+ |> should.equal(
+ map.from_list([tuple("a", 0), tuple("b", 1), tuple("c", 2), tuple("z", 0)]),
+ )
}
pub fn fold_test() {
- let dict = map.from_list([
- tuple("a", 0),
- tuple("b", 1),
- tuple("c", 2),
- tuple("d", 3),
- ])
-
- let add = fn(_, v, acc) {
- v + acc
- }
+ let dict = map.from_list(
+ [tuple("a", 0), tuple("b", 1), tuple("c", 2), tuple("d", 3)],
+ )
+
+ let add = fn(_, v, acc) { v + acc }
dict
- |> map.fold(_, 0, add)
- |> should.equal(_, 6)
+ |> map.fold(0, add)
+ |> should.equal(6)
- let concat = fn(k, _, acc) {
- string.append(acc, k)
- }
+ let concat = fn(k, _, acc) { string.append(acc, k) }
dict
- |> map.fold(_, "", concat)
- |> should.equal(_, "abcd")
+ |> map.fold("", concat)
+ |> should.equal("abcd")
map.from_list([])
- |> map.fold(_, 0, add)
- |> should.equal(_, 0)
+ |> map.fold(0, add)
+ |> should.equal(0)
}
diff --git a/test/gleam/order_test.gleam b/test/gleam/order_test.gleam
index d071775..4457553 100644
--- a/test/gleam/order_test.gleam
+++ b/test/gleam/order_test.gleam
@@ -3,109 +3,109 @@ import gleam/order.{Lt, Eq, Gt}
pub fn reverse_test() {
order.reverse(Lt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.reverse(order.Eq)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.reverse(Gt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
}
pub fn to_int_test() {
order.to_int(Lt)
- |> should.equal(_, -1)
+ |> should.equal(-1)
order.to_int(order.Eq)
- |> should.equal(_, 0)
+ |> should.equal(0)
order.to_int(Gt)
- |> should.equal(_, 1)
+ |> should.equal(1)
}
pub fn compare_test() {
order.compare(Lt, Lt)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.compare(Lt, order.Eq)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.compare(Lt, Gt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.compare(order.Eq, Lt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.compare(order.Eq, order.Eq)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.compare(order.Eq, Gt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.compare(Gt, Lt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.compare(Gt, order.Eq)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.compare(Gt, Gt)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
}
pub fn max_test() {
order.max(Lt, Lt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.max(Lt, order.Eq)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.max(Lt, Gt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.max(order.Eq, Lt)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.max(order.Eq, order.Eq)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.max(order.Eq, Gt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.max(Gt, Lt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.max(Gt, order.Eq)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
order.max(Gt, Gt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
}
pub fn min_test() {
order.min(Lt, Lt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.min(Lt, order.Eq)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.min(Lt, Gt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.min(order.Eq, Lt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.min(order.Eq, order.Eq)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.min(order.Eq, Gt)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.min(Gt, Lt)
- |> should.equal(_, Lt)
+ |> should.equal(Lt)
order.min(Gt, order.Eq)
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
order.min(Gt, Gt)
- |> should.equal(_, Gt)
+ |> should.equal(Gt)
}
diff --git a/test/gleam/pair_test.gleam b/test/gleam/pair_test.gleam
index d9a5eb6..6b88887 100644
--- a/test/gleam/pair_test.gleam
+++ b/test/gleam/pair_test.gleam
@@ -4,59 +4,55 @@ import gleam/pair
pub fn first_test() {
tuple(1, 2)
|> pair.first
- |> should.equal(_, 1)
+ |> should.equal(1)
tuple("abc", [])
|> pair.first
- |> should.equal(_, "abc")
+ |> should.equal("abc")
}
pub fn second_test() {
tuple(1, 2)
|> pair.second
- |> should.equal(_, 2)
+ |> should.equal(2)
tuple("abc", [])
|> pair.second
- |> should.equal(_,[])
+ |> should.equal([])
}
pub fn swap_test() {
tuple(1, "2")
|> pair.swap
- |> should.equal(_, tuple("2", 1))
+ |> should.equal(tuple("2", 1))
}
pub fn map_first_test() {
- let inc = fn(a) {
- a + 1
- }
+ let inc = fn(a) { a + 1 }
pair.map_first(tuple(1, 2), inc)
- |> should.equal(_, tuple(2, 2))
+ |> should.equal(tuple(2, 2))
- pair.map_first(tuple(8,2), inc)
- |> should.equal(_, tuple(9, 2))
+ pair.map_first(tuple(8, 2), inc)
+ |> should.equal(tuple(9, 2))
- pair.map_first(tuple(0,-2), inc)
- |> should.equal(_, tuple(1, -2))
+ pair.map_first(tuple(0, -2), inc)
+ |> should.equal(tuple(1, -2))
pair.map_first(tuple(-10, 20), inc)
- |> should.equal(_, tuple(-9, 20))
+ |> should.equal(tuple(-9, 20))
}
pub fn map_second_test() {
- let dec = fn(a) {
- a - 1
- }
+ let dec = fn(a) { a - 1 }
pair.map_second(tuple(1, 2), dec)
- |> should.equal(_, tuple(1, 1))
+ |> should.equal(tuple(1, 1))
- pair.map_second(tuple(8,2), dec)
- |> should.equal(_, tuple(8, 1))
+ pair.map_second(tuple(8, 2), dec)
+ |> should.equal(tuple(8, 1))
- pair.map_second(tuple(0,-2), dec)
- |> should.equal(_, tuple(0, -3))
+ pair.map_second(tuple(0, -2), dec)
+ |> should.equal(tuple(0, -3))
pair.map_second(tuple(-10, 20), dec)
- |> should.equal(_, tuple(-10, 19))
+ |> should.equal(tuple(-10, 19))
}
diff --git a/test/gleam/result_test.gleam b/test/gleam/result_test.gleam
index 2d2f344..7eb55c4 100644
--- a/test/gleam/result_test.gleam
+++ b/test/gleam/result_test.gleam
@@ -19,70 +19,70 @@ pub fn is_error_test() {
pub fn map_test() {
Ok(1)
- |> result.map(_, fn(x) { x + 1 })
- |> should.equal(_, Ok(2))
+ |> result.map(fn(x) { x + 1 })
+ |> should.equal(Ok(2))
Ok(1)
- |> result.map(_, fn(_) { "2" })
- |> should.equal(_, Ok("2"))
+ |> result.map(fn(_) { "2" })
+ |> should.equal(Ok("2"))
Error(1)
- |> result.map(_, fn(x) { x + 1 })
- |> should.equal(_, Error(1))
+ |> result.map(fn(x) { x + 1 })
+ |> should.equal(Error(1))
}
pub fn map_error_test() {
Ok(1)
- |> result.map_error(_, fn(x) { x + 1 })
- |> should.equal(_, Ok(1))
+ |> result.map_error(fn(x) { x + 1 })
+ |> should.equal(Ok(1))
Error(1)
- |> result.map_error(_, fn(x) { tuple("ok", x + 1) })
- |> should.equal(_, Error(tuple("ok", 2)))
+ |> result.map_error(fn(x) { tuple("ok", x + 1) })
+ |> should.equal(Error(tuple("ok", 2)))
}
pub fn flatten_test() {
Ok(Ok(1))
|> result.flatten
- |> should.equal(_, Ok(1))
+ |> should.equal(Ok(1))
Ok(Error(1))
|> result.flatten
- |> should.equal(_, Error(1))
+ |> should.equal(Error(1))
Error(1)
|> result.flatten
- |> should.equal(_, Error(1))
+ |> should.equal(Error(1))
Error(Error(1))
|> result.flatten
- |> should.equal(_, Error(Error(1)))
+ |> should.equal(Error(Error(1)))
}
pub fn then_test() {
Error(1)
- |> result.then(_, fn(x) { Ok(x + 1) })
- |> should.equal(_, Error(1))
+ |> result.then(fn(x) { Ok(x + 1) })
+ |> should.equal(Error(1))
Ok(1)
- |> result.then(_, fn(x) { Ok(x + 1) })
- |> should.equal(_, Ok(2))
+ |> result.then(fn(x) { Ok(x + 1) })
+ |> should.equal(Ok(2))
Ok(1)
- |> result.then(_, fn(_) { Ok("type change") })
- |> should.equal(_, Ok("type change"))
+ |> result.then(fn(_) { Ok("type change") })
+ |> should.equal(Ok("type change"))
Ok(1)
- |> result.then(_, fn(_) { Error(1) })
- |> should.equal(_, Error(1))
+ |> result.then(fn(_) { Error(1) })
+ |> should.equal(Error(1))
}
pub fn unwrap_test() {
Ok(1)
- |> result.unwrap(_, 50)
- |> should.equal(_, 1)
+ |> result.unwrap(50)
+ |> should.equal(1)
Error("nope")
- |> result.unwrap(_, 50)
- |> should.equal(_, 50)
+ |> result.unwrap(50)
+ |> should.equal(50)
}
diff --git a/test/gleam/string_test.gleam b/test/gleam/string_test.gleam
index 133bdf5..15ace70 100644
--- a/test/gleam/string_test.gleam
+++ b/test/gleam/string_test.gleam
@@ -4,114 +4,108 @@ import gleam/order
pub fn length_test() {
string.length("ß↑e̊")
- |> should.equal(_, 3)
+ |> should.equal(3)
string.length("Gleam")
- |> should.equal(_, 5)
+ |> should.equal(5)
string.length("")
- |> should.equal(_, 0)
+ |> should.equal(0)
}
pub fn lowercase_test() {
string.lowercase("Gleam")
- |> should.equal(_, "gleam")
+ |> should.equal("gleam")
}
pub fn uppercase_test() {
string.uppercase("Gleam")
- |> should.equal(_, "GLEAM")
+ |> should.equal("GLEAM")
}
pub fn reverse_test() {
string.reverse("Gleam")
- |> should.equal(_, "maelG")
+ |> should.equal("maelG")
}
pub fn split_test() {
"Gleam,Erlang,Elixir"
- |> string.split(_, ",")
- |> should.equal(_, ["Gleam", "Erlang", "Elixir"])
+ |> string.split(",")
+ |> should.equal(["Gleam", "Erlang", "Elixir"])
"Gleam, Erlang,Elixir"
- |> string.split(_, ", ")
- |> should.equal(_, ["Gleam", "Erlang,Elixir"])
+ |> string.split(", ")
+ |> should.equal(["Gleam", "Erlang,Elixir"])
}
pub fn replace_test() {
"Gleam,Erlang,Elixir"
- |> string.replace(_, ",", "++")
- |> should.equal(_, "Gleam++Erlang++Elixir")
+ |> string.replace(",", "++")
+ |> should.equal("Gleam++Erlang++Elixir")
}
pub fn append_test() {
"Test"
- |> string.append(_, " Me")
- |> should.equal(_, "Test Me")
+ |> string.append(" Me")
+ |> should.equal("Test Me")
}
pub fn compare_test() {
string.compare("", "")
- |> should.equal(_, order.Eq)
+ |> should.equal(order.Eq)
string.compare("a", "")
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
string.compare("a", "A")
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
string.compare("A", "B")
- |> should.equal(_, order.Lt)
+ |> should.equal(order.Lt)
string.compare("t", "ABC")
- |> should.equal(_, order.Gt)
+ |> should.equal(order.Gt)
}
pub fn contains_test() {
- "gleam"
- |> string.contains(_, "ea")
- |> should.equal(_, True)
+ "gleam"
+ |> string.contains("ea")
+ |> should.equal(True)
- "gleam"
- |> string.contains(_, "x")
- |> should.equal(_, False)
+ "gleam"
+ |> string.contains("x")
+ |> should.equal(False)
- string.contains(does: "bellwether", contain: "bell")
- |> should.equal(_, True)
+ string.contains(does: "bellwether", contain: "bell")
+ |> should.equal(True)
}
pub fn concat_test() {
- [
- "Hello", ", ", "world!",
- ]
+ ["Hello", ", ", "world!"]
|> string.concat
- |> should.equal(_, "Hello, world!")
+ |> should.equal("Hello, world!")
}
pub fn repeat_test() {
"hi"
- |> string.repeat(_, times: 3)
- |> should.equal(_, "hihihi")
+ |> string.repeat(times: 3)
+ |> should.equal("hihihi")
"hi"
- |> string.repeat(_, 0)
- |> should.equal(_, "")
+ |> string.repeat(0)
+ |> should.equal("")
"hi"
- |> string.repeat(_, -1)
- |> should.equal(_, "")
+ |> string.repeat(-1)
+ |> should.equal("")
}
pub fn join_test() {
- [
- "Hello", "world!",
- ]
- |> string.join(_, with: ", ")
- |> should.equal(_, "Hello, world!")
-
- [
- "Hello", "world!",
- ]
- |> string.join(_, with: "-")
- |> should.equal(_, "Hello-world!")
+ ["Hello", "world!"]
+ |> string.join(with: ", ")
+ |> should.equal("Hello, world!")
+
+ ["Hello", "world!"]
+ |> string.join(with: "-")
+ |> should.equal("Hello-world!")
}