diff options
author | E Jikan <e@vstream-corp.com> | 2022-04-15 15:53:09 -0700 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-04-16 11:17:19 +0100 |
commit | ee95f4b1149778d36f1b570779b87402aade702e (patch) | |
tree | aa44cd3d0529f0a528ac255230c8dac2bbc3e633 | |
parent | cb9e4cae4c7bd3f8a9bfa3bd7d4d5fecf7f18fc7 (diff) | |
download | gleam_stdlib-ee95f4b1149778d36f1b570779b87402aade702e.tar.gz gleam_stdlib-ee95f4b1149778d36f1b570779b87402aade702e.zip |
style: Use backticks for code blocks
-rw-r--r-- | src/gleam/bit_string.gleam | 12 | ||||
-rw-r--r-- | src/gleam/bool.gleam | 138 | ||||
-rw-r--r-- | src/gleam/float.gleam | 116 | ||||
-rw-r--r-- | src/gleam/int.gleam | 160 | ||||
-rw-r--r-- | src/gleam/io.gleam | 36 | ||||
-rw-r--r-- | src/gleam/iterator.gleam | 346 | ||||
-rw-r--r-- | src/gleam/list.gleam | 508 | ||||
-rw-r--r-- | src/gleam/map.gleam | 176 | ||||
-rw-r--r-- | src/gleam/option.gleam | 146 | ||||
-rw-r--r-- | src/gleam/order.gleam | 46 | ||||
-rw-r--r-- | src/gleam/pair.gleam | 30 | ||||
-rw-r--r-- | src/gleam/queue.gleam | 118 | ||||
-rw-r--r-- | src/gleam/regex.gleam | 92 | ||||
-rw-r--r-- | src/gleam/result.gleam | 118 | ||||
-rw-r--r-- | src/gleam/set.gleam | 80 | ||||
-rw-r--r-- | src/gleam/string.gleam | 230 | ||||
-rw-r--r-- | src/gleam/string_builder.gleam | 24 |
17 files changed, 1414 insertions, 962 deletions
diff --git a/src/gleam/bit_string.gleam b/src/gleam/bit_string.gleam index eee006c..410c712 100644 --- a/src/gleam/bit_string.gleam +++ b/src/gleam/bit_string.gleam @@ -38,8 +38,10 @@ if javascript { /// /// ## Examples /// -/// > append(to: from_string("butter"), suffix: from_string("fly")) -/// from_string("butterfly") +/// ```gleam +/// > append(to: from_string("butter"), suffix: from_string("fly")) +/// from_string("butterfly") +/// ``` /// pub fn append(to first: BitString, suffix second: BitString) -> BitString { concat([first, second]) @@ -133,8 +135,10 @@ if javascript { /// /// ## Examples /// -/// > concat([from_string("butter"), from_string("fly")]) -/// from_string("butterfly") +/// ```gleam +/// > concat([from_string("butter"), from_string("fly")]) +/// from_string("butterfly") +/// ``` /// pub fn concat(bit_strings: List(BitString)) -> BitString { do_concat(bit_strings) diff --git a/src/gleam/bool.gleam b/src/gleam/bool.gleam index 6728d00..557aabd 100644 --- a/src/gleam/bool.gleam +++ b/src/gleam/bool.gleam @@ -14,11 +14,13 @@ import gleam/order.{Order} /// /// ## Examples /// -/// > negate(True) -/// False +/// ```gleam +/// > negate(True) +/// False /// -/// > negate(False) -/// True +/// > negate(False) +/// True +/// ``` /// pub fn negate(bool: Bool) -> Bool { case bool { @@ -31,17 +33,19 @@ pub fn negate(bool: Bool) -> Bool { /// /// ## Examples /// -/// > nor(False, False) -/// True +/// ```gleam +/// > nor(False, False) +/// True /// -/// > nor(False, True) -/// False +/// > nor(False, True) +/// False /// -/// > nor(True, False) -/// False +/// > nor(True, False) +/// False /// -/// > nor(True, True) -/// False +/// > nor(True, True) +/// False +/// ``` /// pub fn nor(a: Bool, b: Bool) -> Bool { case a, b { @@ -56,17 +60,19 @@ pub fn nor(a: Bool, b: Bool) -> Bool { /// /// ## Examples /// -/// > nand(False, False) -/// True +/// ```gleam +/// > nand(False, False) +/// True /// -/// > nand(False, True) -/// True +/// > nand(False, True) +/// True /// -/// > nand(True, False) -/// True +/// > nand(True, False) +/// True /// -/// > nand(True, True) -/// False +/// > nand(True, True) +/// False +/// ``` /// pub fn nand(a: Bool, b: Bool) -> Bool { case a, b { @@ -81,17 +87,19 @@ pub fn nand(a: Bool, b: Bool) -> Bool { /// /// ## Examples /// -/// > exclusive_or(False, False) -/// False +/// ```gleam +/// > exclusive_or(False, False) +/// False /// -/// > exclusive_or(False, True) -/// True +/// > exclusive_or(False, True) +/// True /// -/// > exclusive_or(True, False) -/// True +/// > exclusive_or(True, False) +/// True /// -/// > exclusive_or(True, True) -/// False +/// > exclusive_or(True, True) +/// False +/// ``` /// pub fn exclusive_or(a: Bool, b: Bool) -> Bool { case a, b { @@ -106,17 +114,19 @@ pub fn exclusive_or(a: Bool, b: Bool) -> Bool { /// /// ## Examples /// -/// > exclusive_nor(False, False) -/// True +/// ```gleam +/// > exclusive_nor(False, False) +/// True /// -/// > exclusive_nor(False, True) -/// False +/// > exclusive_nor(False, True) +/// False /// -/// > exclusive_nor(True, False) -/// False +/// > exclusive_nor(True, False) +/// False /// -/// > exclusive_nor(True, True) -/// True +/// > exclusive_nor(True, True) +/// True +/// ``` /// pub fn exclusive_nor(a: Bool, b: Bool) -> Bool { case a, b { @@ -131,9 +141,11 @@ pub fn exclusive_nor(a: Bool, b: Bool) -> Bool { /// /// ## Examples /// -/// > import gleam/order -/// > compare(True, False) -/// order.Gt +/// ```gleam +/// > import gleam/order +/// > compare(True, False) +/// order.Gt +/// ``` /// pub fn compare(a: Bool, with b: Bool) -> Order { case a, b { @@ -148,14 +160,16 @@ pub fn compare(a: Bool, with b: Bool) -> Order { /// /// ## Examples /// -/// > max(True, False) -/// True +/// ```gleam +/// > max(True, False) +/// True /// -/// > max(False, True) -/// True +/// > max(False, True) +/// True /// -/// > max(False, False) -/// False +/// > max(False, False) +/// False +/// ``` /// pub fn max(a: Bool, b: Bool) -> Bool { case a { @@ -168,14 +182,16 @@ pub fn max(a: Bool, b: Bool) -> Bool { /// /// ## Examples /// -/// > min(True, False) -/// False +/// ```gleam +/// > min(True, False) +/// False /// -/// > min(False, True) -/// False +/// > min(False, True) +/// False /// -/// > min(False, False) -/// False +/// > min(False, False) +/// False +/// ``` /// pub fn min(a: Bool, b: Bool) -> Bool { case a { @@ -188,11 +204,13 @@ pub fn min(a: Bool, b: Bool) -> Bool { /// /// ## Examples /// -/// > to_int(True) -/// 1 +/// ```gleam +/// > to_int(True) +/// 1 /// -/// > to_int(False) -/// 0 +/// > to_int(False) +/// 0 +/// ``` /// pub fn to_int(bool: Bool) -> Int { case bool { @@ -205,11 +223,13 @@ pub fn to_int(bool: Bool) -> Int { /// /// ## Examples /// -/// > to_string(True) -/// "True" +/// ```gleam +/// > to_string(True) +/// "True" /// -/// > to_string(False) -/// "False" +/// > to_string(False) +/// "False" +/// ``` /// pub fn to_string(bool: Bool) -> String { case bool { diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam index 0f824a7..e54290f 100644 --- a/src/gleam/float.gleam +++ b/src/gleam/float.gleam @@ -5,11 +5,13 @@ import gleam/string_builder /// possible. /// /// ## Examples -/// > parse("2.3") -/// Ok(2.3) +/// ```gleam +/// > parse("2.3") +/// Ok(2.3) /// -/// > parse("ABC") -/// Error(Nil) +/// > parse("ABC") +/// Error(Nil) +/// ``` /// pub fn parse(string: String) -> Result(Float, Nil) { do_parse(string) @@ -28,8 +30,10 @@ if javascript { /// Returns the string representation of the provided `Float`. /// /// ## Examples -/// > to_string(2.3) -/// "2.3" +/// ```gleam +/// > to_string(2.3) +/// "2.3" +/// ``` /// pub fn to_string(f: Float) -> String { f @@ -55,8 +59,10 @@ pub fn clamp(n: Float, min min_bound: Float, max max_bound: Float) -> Float { /// Compares two `Float`s, returning an order. /// /// ## Examples -/// > compare(2.0, 2.3) -/// Lt +/// ```gleam +/// > compare(2.0, 2.3) +/// Lt +/// ``` /// pub fn compare(a: Float, with b: Float) -> Order { case a == b { @@ -74,8 +80,10 @@ pub fn compare(a: Float, with b: Float) -> Order { /// e.g. 5.3 - 5.0 is not exactly 0.3 in a float /// /// ## Examples -/// > loosely_compare(5.0, with: 5.3, tolerating: 0.5) -/// Eq +/// ```gleam +/// > loosely_compare(5.0, with: 5.3, tolerating: 0.5) +/// Eq +/// ``` /// pub fn loosely_compare( a: Float, @@ -93,8 +101,10 @@ pub fn loosely_compare( /// /// ## Examples /// -/// > min(2.0, 2.3) -/// 2.0 +/// ```gleam +/// > min(2.0, 2.3) +/// 2.0 +/// ``` /// pub fn min(a: Float, b: Float) -> Float { case a <. b { @@ -107,8 +117,10 @@ pub fn min(a: Float, b: Float) -> Float { /// /// ## Examples /// -/// > max(2.0, 2.3) -/// 2.3 +/// ```gleam +/// > max(2.0, 2.3) +/// 2.3 +/// ``` /// pub fn max(a: Float, b: Float) -> Float { case a >. b { @@ -121,8 +133,10 @@ pub fn max(a: Float, b: Float) -> Float { /// /// ## Examples /// -/// > ceiling(2.3) -/// 3.0 +/// ```gleam +/// > ceiling(2.3) +/// 3.0 +/// ``` /// pub fn ceiling(float: Float) -> Float { do_ceiling(float) @@ -142,8 +156,10 @@ if javascript { /// /// ## Examples /// -/// > floor(2.3) -/// 2.0 +/// ```gleam +/// > floor(2.3) +/// 2.0 +/// ``` /// pub fn floor(float: Float) -> Float { do_floor(float) @@ -163,11 +179,13 @@ if javascript { /// /// ## Examples /// -/// > round(2.3) -/// 2 +/// ```gleam +/// > round(2.3) +/// 2 /// -/// > round(2.5) -/// 3 +/// > round(2.5) +/// 3 +/// ``` /// pub fn round(float: Float) -> Int { do_round(float) @@ -194,8 +212,10 @@ if javascript { /// /// ## Examples /// -/// > truncate(2.4343434847383438) -/// 2 +/// ```gleam +/// > truncate(2.4343434847383438) +/// 2 +/// ``` /// pub fn truncate(float: Float) -> Int { do_truncate(float) @@ -215,11 +235,13 @@ if javascript { /// /// ## Examples /// -/// > absolute_value(-12.5) -/// 12.5 +/// ```gleam +/// > absolute_value(-12.5) +/// 12.5 /// -/// > absolute_value(10.2) -/// 10.2 +/// > absolute_value(10.2) +/// 10.2 +/// ``` /// pub fn absolute_value(float: Float) -> Float { case float >=. 0. { @@ -233,11 +255,13 @@ pub fn absolute_value(float: Float) -> Float { /// /// ## Examples /// -/// > power(2.0, 2.0) -/// 4.0 +/// ```gleam +/// > power(2.0, 2.0) +/// 4.0 /// -/// > power(8.0, 1.5) -/// 22.627416997969522 +/// > power(8.0, 1.5) +/// 22.627416997969522 +/// ``` /// pub fn power(base: Float, exponent: Float) -> Float { do_power(base, exponent) @@ -257,11 +281,13 @@ if javascript { /// /// ## Examples /// -/// > square_root(4.0) -/// Ok(2.0) +/// ```gleam +/// > square_root(4.0) +/// Ok(2.0) /// -/// > square_root(-16.0) -/// Error(Nil) +/// > square_root(-16.0) +/// Error(Nil) +/// ``` /// pub fn square_root(number: Float) -> Result(Float, Nil) { case number <. 0.0 { @@ -274,8 +300,10 @@ pub fn square_root(number: Float) -> Result(Float, Nil) { /// /// ## Examples /// -/// > negate(1.) -/// -1. +/// ```gleam +/// > negate(1.) +/// -1. +/// ``` /// pub fn negate(x: Float) -> Float { -1. *. x @@ -285,8 +313,10 @@ pub fn negate(x: Float) -> Float { /// /// ## Example /// -/// > sum([1.0, 2.2, 3.3]) -/// 6.5 +/// ```gleam +/// > sum([1.0, 2.2, 3.3]) +/// 6.5 +/// ``` /// pub fn sum(numbers: List(Float)) -> Float { numbers @@ -304,8 +334,10 @@ fn do_sum(numbers: List(Float), initial: Float) -> Float { /// /// ## Example /// -/// > product([2.5, 3.2, 4.2]) -/// 33.6 +/// ```gleam +/// > product([2.5, 3.2, 4.2]) +/// 33.6 +/// ``` /// pub fn product(numbers: List(Float)) -> Float { case numbers { diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam index e637cd5..69c8742 100644 --- a/src/gleam/int.gleam +++ b/src/gleam/int.gleam @@ -5,11 +5,13 @@ import gleam/float /// /// ## Examples /// -/// > absolute_value(-12) -/// 12 +/// ```gleam +/// > absolute_value(-12) +/// 12 /// -/// > absolute_value(10) -/// 10 +/// > absolute_value(10) +/// 10 +/// ``` /// pub fn absolute_value(num: Int) -> Int { case num >= 0 { @@ -22,11 +24,13 @@ pub fn absolute_value(num: Int) -> Int { /// /// ## Examples /// -/// > parse("2") -/// Ok(2) +/// ```gleam +/// > parse("2") +/// Ok(2) /// -/// > parse("ABC") -/// Error(Nil) +/// > parse("ABC") +/// Error(Nil) +/// ``` /// pub fn parse(string) { do_parse(string) @@ -46,8 +50,10 @@ if javascript { /// /// ## Examples /// -/// > to_string(2) -/// "2" +/// ```gleam +/// > to_string(2) +/// "2" +/// ``` /// pub fn to_string(int) { do_to_string(int) @@ -74,20 +80,22 @@ pub type InvalidBase { /// /// ## Examples /// -/// > to_base_string(2, 2) -/// Ok("10") +/// ```gleam +/// > to_base_string(2, 2) +/// Ok("10") /// -/// > to_base_string(48, 16) -/// Ok("30") +/// > to_base_string(48, 16) +/// Ok("30") /// -/// > to_base_string(48, 36) -/// Ok("1C") +/// > to_base_string(48, 36) +/// Ok("1C") /// -/// > to_base_string(48, 1) -/// Error(InvalidBase) +/// > to_base_string(48, 1) +/// Error(InvalidBase) /// -/// > to_base_string(48, 37) -/// Error(InvalidBase) +/// > to_base_string(48, 37) +/// Error(InvalidBase) +/// ``` /// pub fn to_base_string(int, base) -> Result(String, InvalidBase) { case base >= 2 && base <= 36 { @@ -110,8 +118,10 @@ if javascript { /// /// ## Examples /// -/// > to_base2(2) -/// "10" +/// ```gleam +/// > to_base2(2) +/// "10" +/// ``` /// pub fn to_base2(int) { do_to_base_string(int, 2) @@ -121,8 +131,10 @@ pub fn to_base2(int) { /// /// ## Examples /// -/// > to_base8(15) -/// "17" +/// ```gleam +/// > to_base8(15) +/// "17" +/// ``` /// pub fn to_base8(int) { do_to_base_string(int, 8) @@ -132,8 +144,10 @@ pub fn to_base8(int) { /// /// ## Examples /// -/// > to_base16(48) -/// "30" +/// ```gleam +/// > to_base16(48) +/// "30" +/// ``` /// pub fn to_base16(int) { do_to_base_string(int, 16) @@ -143,8 +157,10 @@ pub fn to_base16(int) { /// /// ## Examples /// -/// > to_base36(48) -/// "1C" +/// ```gleam +/// > to_base36(48) +/// "1C" +/// ``` /// pub fn to_base36(int) { do_to_base_string(int, 36) @@ -198,14 +214,16 @@ pub fn clamp(n: Int, min min_bound: Int, max max_bound: Int) -> Int { /// /// ## Examples /// -/// > compare(2, 3) -/// Lt +/// ```gleam +/// > compare(2, 3) +/// Lt /// -/// > compare(4, 3) -/// Gt +/// > compare(4, 3) +/// Gt /// -/// > compare(3, 3) -/// Eq +/// > compare(3, 3) +/// Eq +/// ``` /// pub fn compare(a: Int, with b: Int) -> Order { case a == b { @@ -222,8 +240,10 @@ pub fn compare(a: Int, with b: Int) -> Order { /// /// ## Examples /// -/// > min(2, 3) -/// 2 +/// ```gleam +/// > min(2, 3) +/// 2 +/// ``` /// pub fn min(a: Int, b: Int) -> Int { case a < b { @@ -236,8 +256,10 @@ pub fn min(a: Int, b: Int) -> Int { /// /// ## Examples /// -/// > max(2, 3) -/// 3 +/// ```gleam +/// > max(2, 3) +/// 3 +/// ``` /// pub fn max(a: Int, b: Int) -> Int { case a > b { @@ -250,11 +272,13 @@ pub fn max(a: Int, b: Int) -> Int { /// /// ## Examples /// -/// > is_even(2) -/// True +/// ```gleam +/// > is_even(2) +/// True /// -/// > is_even(3) -/// False +/// > is_even(3) +/// False +/// ``` /// pub fn is_even(x: Int) -> Bool { x % 2 == 0 @@ -264,11 +288,13 @@ pub fn is_even(x: Int) -> Bool { /// /// ## Examples /// -/// > is_odd(3) -/// True +/// ```gleam +/// > is_odd(3) +/// True /// -/// > is_odd(2) -/// False +/// > is_odd(2) +/// False +/// ``` /// pub fn is_odd(x: Int) -> Bool { x % 2 != 0 @@ -278,8 +304,10 @@ pub fn is_odd(x: Int) -> Bool { /// /// ## Examples /// -/// > negate(1) -/// -1 +/// ```gleam +/// > negate(1) +/// -1 +/// ``` /// pub fn negate(x: Int) -> Int { -1 * x @@ -289,8 +317,10 @@ pub fn negate(x: Int) -> Int { /// /// ## Example /// -/// > sum([1, 2, 3]) -/// 6 +/// ```gleam +/// > sum([1, 2, 3]) +/// 6 +/// ``` /// pub fn sum(numbers: List(Int)) -> Int { numbers @@ -308,8 +338,10 @@ fn do_sum(numbers: List(Int), initial: Int) -> Int { /// /// ## Example /// -/// > product([2, 3, 4]) -/// 24 +/// ```gleam +/// > product([2, 3, 4]) +/// 24 +/// ``` /// pub fn product(numbers: List(Int)) -> Int { case numbers { @@ -329,11 +361,13 @@ fn do_product(numbers: List(Int), initial: Int) -> Int { /// /// ## Examples /// -/// > digits(234, 10) -/// Ok([2,3,4]) +/// ```gleam +/// > digits(234, 10) +/// Ok([2,3,4]) /// -/// > digits(234, 1) -/// Error(InvalidBase) +/// > digits(234, 1) +/// Error(InvalidBase) +/// ``` /// pub fn digits(number: Int, base: Int) -> Result(List(Int), InvalidBase) { case base < 2 { @@ -354,14 +388,16 @@ fn do_digits(number: Int, base: Int, acc: List(Int)) -> List(Int) { /// /// ## Examples /// -/// > undigits([2,3,4], 10) -/// Ok(234) +/// ```gleam +/// > undigits([2,3,4], 10) +/// Ok(234) /// -/// > undigits([2,3,4], 1) -/// Error(InvalidBase) +/// > undigits([2,3,4], 1) +/// Error(InvalidBase) /// -/// > undigits([2,3,4], 2) -/// Error(InvalidBase) +/// > undigits([2,3,4], 2) +/// Error(InvalidBase) +/// ``` /// pub fn undigits(numbers: List(Int), base: Int) -> Result(Int, InvalidBase) { case base < 2 { diff --git a/src/gleam/io.gleam b/src/gleam/io.gleam index df96128..5a485c9 100644 --- a/src/gleam/io.gleam +++ b/src/gleam/io.gleam @@ -28,9 +28,11 @@ if javascript { /// /// ## Example /// -/// > io.println("Hi mum") -/// // -> Hi mum -/// Nil +/// ```gleam +/// > io.println("Hi mum") +/// // -> Hi mum +/// Nil +/// ``` /// pub fn println(string: String) -> Nil { do_println(string) @@ -52,21 +54,23 @@ if javascript { /// /// ## Example /// -/// > io.debug("Hi mum") -/// // -> <<"Hi mum">> -/// "Hi mum" +/// ```gleam +/// > io.debug("Hi mum") +/// // -> <<"Hi mum">> +/// "Hi mum" /// -/// > io.debug(Ok(1)) -/// // -> {ok, 1} -/// Ok(1) +/// > io.debug(Ok(1)) +/// // -> {ok, 1} +/// Ok(1) /// -/// > import list -/// > [1, 2] -/// > |> list.map(fn(x) { x + 1 }) -/// > |> io.debug -/// > |> list.map(fn(x) { x * 2 }) -/// // -> [2, 3] -/// [4, 6] +/// > import list +/// > [1, 2] +/// > |> list.map(fn(x) { x + 1 }) +/// > |> io.debug +/// > |> list.map(fn(x) { x * 2 }) +/// // -> [2, 3] +/// [4, 6] +/// ``` /// pub fn debug(term: anything) -> anything { debug_print(term) diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index c2481ea..a4f8e38 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -57,14 +57,16 @@ fn do_unfold( /// /// ## Examples /// -/// > unfold(from: 5, with: fn(n) { -/// > case n { -/// > 0 -> Done -/// > n -> Next(element: n, accumulator: n - 1) -/// > } -/// > }) -/// > |> to_list -/// [5, 4, 3, 2, 1] +/// ```gleam +/// > unfold(from: 5, with: fn(n) { +/// > case n { +/// > 0 -> Done +/// > n -> Next(element: n, accumulator: n - 1) +/// > } +/// > }) +/// > |> to_list +/// [5, 4, 3, 2, 1] +/// ``` /// pub fn unfold( from initial: acc, @@ -87,10 +89,12 @@ pub fn repeatedly(f: fn() -> element) -> Iterator(element) { /// /// ## Examples /// -/// > repeat(10) -/// > |> take(4) -/// > |> to_list -/// [10, 10, 10, 10] +/// ```gleam +/// > repeat(10) +/// > |> take(4) +/// > |> to_list +/// [10, 10, 10, 10] +/// ``` /// pub fn repeat(x: element) -> Iterator(element) { repeatedly(fn() { x }) @@ -100,8 +104,10 @@ pub fn repeat(x: element) -> Iterator(element) { /// /// ## Examples /// -/// > from_list([1, 2, 3, 4]) |> to_list -/// [1, 2, 3, 4] +/// ```gleam +/// > from_list([1, 2, 3, 4]) |> to_list +/// [1, 2, 3, 4] +/// ``` /// pub fn from_list(list: List(element)) -> Iterator(element) { let yield = fn(acc) { @@ -136,10 +142,12 @@ fn do_fold( /// /// ## Examples /// -/// > [1, 2, 3, 4] -/// > |> from_list -/// > |> fold(from: 0, with: fn(acc, element) { element + acc }) -/// 10 +/// ```gleam +/// > [1, 2, 3, 4] +/// > |> from_list +/// > |> fold(from: 0, with: fn(acc, element) { element + acc }) +/// 10 +/// ``` /// pub fn fold( over iterator: Iterator(e), @@ -184,18 +192,20 @@ pub fn to_list(iterator: Iterator(element)) -> List(element) { /// /// ## Examples /// -/// > assert Next(head, tail) = -/// > [1, 2, 3, 4] -/// > |> from_list -/// > |> step -/// > head -/// 1 +/// ```gleam +/// > assert Next(head, tail) = +/// > [1, 2, 3, 4] +/// > |> from_list +/// > |> step +/// > head +/// 1 /// -/// > tail |> to_list -/// [2, 3, 4] +/// > tail |> to_list +/// [2, 3, 4] /// -/// > empty() |> step -/// Done +/// > empty() |> step +/// Done +/// ``` /// pub fn step(iterator: Iterator(e)) -> Step(e, Iterator(e)) { case iterator.continuation() { @@ -223,11 +233,13 @@ fn do_take(continuation: fn() -> Action(e), desired: Int) -> fn() -> Action(e) { /// /// ## Examples /// -/// > [1, 2, 3, 4, 5] |> from_list |> take(up_to: 3) |> to_list -/// [1, 2, 3] +/// ```gleam +/// > [1, 2, 3, 4, 5] |> from_list |> take(up_to: 3) |> to_list +/// [1, 2, 3] /// -/// > [1, 2] |> from_list |> take(up_to: 3) |> to_list -/// [1, 2] +/// > [1, 2] |> from_list |> take(up_to: 3) |> to_list +/// [1, 2] +/// ``` /// pub fn take(from iterator: Iterator(e), up_to desired: Int) -> Iterator(e) { iterator.continuation @@ -257,11 +269,13 @@ fn do_drop(continuation: fn() -> Action(e), desired: Int) -> Action(e) { /// /// ## Examples /// -/// > [1, 2, 3, 4, 5] |> from_list |> drop(up_to: 3) |> to_list -/// [4, 5] +/// ```gleam +/// > [1, 2, 3, 4, 5] |> from_list |> drop(up_to: 3) |> to_list +/// [4, 5] /// -/// > [1, 2] |> from_list |> drop(up_to: 3) |> to_list -/// [] +/// > [1, 2] |> from_list |> drop(up_to: 3) |> to_list +/// [] +/// ``` /// pub fn drop(from iterator: Iterator(e), up_to desired: Int) -> Iterator(e) { fn() { do_drop(iterator.continuation, desired) } @@ -287,8 +301,10 @@ fn do_map(continuation: fn() -> Action(a), f: fn(a) -> b) -> fn() -> Action(b) { /// /// ## Examples /// -/// > [1, 2, 3] |> from_list |> map(fn(x) { x * 2 }) |> to_list -/// [2, 4, 6] +/// ```gleam +/// > [1, 2, 3] |> from_list |> map(fn(x) { x * 2 }) |> to_list +/// [2, 4, 6] +/// ``` /// pub fn map(over iterator: Iterator(a), with f: fn(a) -> b) -> Iterator(b) { iterator.continuation @@ -310,8 +326,10 @@ fn do_append(first: fn() -> Action(a), second: fn() -> Action(a)) -> Action(a) { /// /// ## Examples /// -/// > [1, 2] |> from_list |> append([3, 4] |> from_list) |> to_list -/// [1, 2, 3, 4] +/// ```gleam +/// > [1, 2] |> from_list |> append([3, 4] |> from_list) |> to_list +/// [1, 2, 3, 4] +/// ``` /// pub fn append(to first: Iterator(a), suffix second: Iterator(a)) -> Iterator(a) { fn() { do_append(first.continuation, second.continuation) } @@ -333,8 +351,10 @@ fn do_flatten(flattened: fn() -> Action(Iterator(a))) -> Action(a) { /// /// ## Examples /// -/// > from_list([[1, 2], [3, 4]]) |> map(from_list) |> flatten |> to_list -/// [1, 2, 3, 4] +/// ```gleam +/// > from_list([[1, 2], [3, 4]]) |> map(from_list) |> flatten |> to_list +/// [1, 2, 3, 4] +/// ``` /// pub fn flatten(iterator: Iterator(Iterator(a))) -> Iterator(a) { fn() { do_flatten(iterator.continuation) } @@ -352,8 +372,10 @@ pub fn flatten(iterator: Iterator(Iterator(a))) -> Iterator(a) { /// /// ## Examples /// -/// > [1, 2] |> from_list |> flat_map(fn(x) { from_list([x, x + 1]) }) |> to_list -/// [1, 2, 2, 3] +/// ```gleam +/// > [1, 2] |> from_list |> flat_map(fn(x) { from_list([x, x + 1]) }) |> to_list +/// [1, 2, 2, 3] +/// ``` /// pub fn flat_map( over iterator: Iterator(a), @@ -388,9 +410,11 @@ fn do_filter( /// /// ## Examples /// -/// > import gleam/int -/// > [1, 2, 3, 4] |> from_list |> filter(int.is_even) |> to_list -/// [2, 4] +/// ```gleam +/// > import gleam/int +/// > [1, 2, 3, 4] |> from_list |> filter(int.is_even) |> to_list +/// [2, 4] +/// ``` /// pub fn filter( iterator: Iterator(a), @@ -404,8 +428,10 @@ pub fn filter( /// /// ## Examples /// -/// > [1, 2] |> from_list |> cycle |> take(6) |> to_list -/// [1, 2, 1, 2, 1, 2] +/// ```gleam +/// > [1, 2] |> from_list |> cycle |> take(6) |> to_list +/// [1, 2, 1, 2, 1, 2] +/// ``` /// pub fn cycle(iterator: Iterator(a)) -> Iterator(a) { repeat(iterator) @@ -417,14 +443,16 @@ pub fn cycle(iterator: Iterator(a)) -> Iterator(a) { /// /// ## Examples /// -/// > range(from: 1, to: 5) |> to_list -/// [1, 2, 3, 4] +/// ```gleam +/// > range(from: 1, to: 5) |> to_list +/// [1, 2, 3, 4] /// -/// > range(from: 1, to: -2) |> to_list -/// [1, 0, -1] +/// > range(from: 1, to: -2) |> to_list +/// [1, 0, -1] /// -/// > range(from: 0, to: 0) |> to_list -/// [] +/// > range(from: 0, to: 0) |> to_list +/// [] +/// ``` /// pub fn range(from start: Int, to stop: Int) -> Iterator(Int) { let increment = case start < stop { @@ -461,14 +489,16 @@ fn do_find(continuation: fn() -> Action(a), f: fn(a) -> Bool) -> Result(a, Nil) /// /// ## Examples /// -/// > find(from_list([1, 2, 3]), fn(x) { x > 2 }) -/// Ok(3) +/// ```gleam +/// > find(from_list([1, 2, 3]), fn(x) { x > 2 }) +/// Ok(3) /// -/// > find(from_list([1, 2, 3]), fn(x) { x > 4 }) -/// Error(Nil) +/// > find(from_list([1, 2, 3]), fn(x) { x > 4 }) +/// Error(Nil) /// -/// > find(empty(), fn(_) { True }) -/// Error(Nil) +/// > find(empty(), fn(_) { True }) +/// Error(Nil) +/// ``` /// pub fn find( in haystack: Iterator(a), @@ -495,8 +525,10 @@ fn do_index( /// /// ## Examples /// -/// > from_list(["a", "b", "c"]) |> index |> to_list -/// [#(0, "a"), #(1, "b"), #(2, "c")] +/// ```gleam +/// > from_list(["a", "b", "c"]) |> index |> to_list +/// [#(0, "a"), #(1, "b"), #(2, "c")] +/// ``` /// pub fn index(over iterator: Iterator(element)) -> Iterator(#(Int, element)) { iterator.continuation @@ -508,8 +540,10 @@ pub fn index(over iterator: Iterator(element)) -> Iterator(#(Int, element)) { /// /// ## Examples /// -/// > iterate(1, fn(n) { n * 3 }) |> take(5) |> to_list -/// [1, 3, 9, 27, 81] +/// ```gleam +/// > iterate(1, fn(n) { n * 3 }) |> take(5) |> to_list +/// [1, 3, 9, 27, 81] +/// ``` /// pub fn iterate( from initial: element, @@ -538,8 +572,10 @@ fn do_take_while( /// /// ## Examples /// -/// > from_list([1, 2, 3, 2, 4]) |> take_while(satisfying: fn(x) { x < 3 }) |> to_list -/// [1, 2] +/// ```gleam +/// > from_list([1, 2, 3, 2, 4]) |> take_while(satisfying: fn(x) { x < 3 }) |> to_list +/// [1, 2] +/// ``` /// pub fn take_while( in iterator: Iterator(element), @@ -569,8 +605,10 @@ fn do_drop_while( /// /// ## Examples /// -/// > from_list([1, 2, 3, 4, 2, 5]) |> drop_while(satisfying: fn(x) { x < 4 }) |> to_list -/// [4, 2, 5] +/// ```gleam +/// > from_list([1, 2, 3, 4, 2, 5]) |> drop_while(satisfying: fn(x) { x < 4 }) |> to_list +/// [4, 2, 5] +/// ``` /// pub fn drop_while( in iterator: Iterator(element), @@ -602,9 +640,11 @@ fn do_scan( /// /// ## Examples /// -/// Generate a sequence of partial sums: -/// > from_list([1, 2, 3, 4, 5]) |> scan(from: 0, with: fn(acc, el) { acc + el }) |> to_list -/// [1, 3, 6, 10, 15] +/// Generate a sequence of partial sums: +/// ```gleam +/// > from_list([1, 2, 3, 4, 5]) |> scan(from: 0, with: fn(acc, el) { acc + el }) |> to_list +/// [1, 3, 6, 10, 15] +/// ``` /// pub fn scan( over iterator: Iterator(element), @@ -638,8 +678,10 @@ fn do_zip( /// /// ## Examples /// -/// > from_list(["a", "b", "c"]) |> zip(range(20, 30)) |> to_list -/// [#("a", 20), #("b", 21), #("c", 22)] +/// ```gleam +/// > from_list(["a", "b", "c"]) |> zip(range(20, 30)) |> to_list +/// [#("a", 20), #("b", 21), #("c", 22)] +/// ``` /// pub fn zip(left: Iterator(a), right: Iterator(b)) -> Iterator(#(a, b)) { do_zip(left.continuation, right.continuation) @@ -688,8 +730,10 @@ fn do_chunk( /// /// ## Examples /// -/// > from_list([1, 2, 2, 3, 4, 4, 6, 7, 7]) |> chunk(by: fn(n) { n % 2 }) |> to_list -/// [[1], [2, 2], [3], [4, 4, 6], [7, 7]] +/// ```gleam +/// > from_list([1, 2, 2, 3, 4, 4, 6, 7, 7]) |> chunk(by: fn(n) { n % 2 }) |> to_list +/// [[1], [2, 2], [3], [4, 4, 6], [7, 7]] +/// ``` /// pub fn chunk( over iterator: Iterator(element), @@ -755,11 +799,13 @@ fn do_sized_chunk( /// /// ## Examples /// -/// > from_list([1, 2, 3, 4, 5, 6]) |> sized_chunk(into: 2) |> to_list -/// [[1, 2], [3, 4], [5, 6]] +/// ```gleam +/// > from_list([1, 2, 3, 4, 5, 6]) |> sized_chunk(into: 2) |> to_list +/// [[1, 2], [3, 4], [5, 6]] /// -/// > from_list([1, 2, 3, 4, 5, 6, 7, 8]) |> sized_chunk(into: 3) |> to_list -/// [[1, 2, 3], [4, 5, 6], [7, 8]] +/// > from_list([1, 2, 3, 4, 5, 6, 7, 8]) |> sized_chunk(into: 3) |> to_list +/// [[1, 2, 3], [4, 5, 6], [7, 8]] +/// ``` /// pub fn sized_chunk( over iterator: Iterator(element), @@ -788,14 +834,16 @@ fn do_intersperse( /// /// ## Examples /// -/// > empty() |> intersperse(with: 0) |> to_list -/// [] +/// ```gleam +/// > empty() |> intersperse(with: 0) |> to_list +/// [] /// -/// > from_list([1]) |> intersperse(with: 0) |> to_list -/// [1] +/// > from_list([1]) |> intersperse(with: 0) |> to_list +/// [1] /// -/// > from_list([1, 2, 3, 4, 5]) |> intersperse(with: 0) |> to_list -/// [1, 0, 2, 0, 3, 0, 4, 0, 5] +/// > from_list([1, 2, 3, 4, 5]) |> intersperse(with: 0) |> to_list +/// [1, 0, 2, 0, 3, 0, 4, 0, 5] +/// ``` /// pub fn intersperse( over iterator: Iterator(element), @@ -829,14 +877,16 @@ fn do_any( /// /// ## Examples /// -/// > empty() |> any(fn(n) { n % 2 == 0 }) -/// False +/// ```gleam +/// > empty() |> any(fn(n) { n % 2 == 0 }) +/// False /// -/// > from_list([1, 2, 5, 7, 9]) |> any(fn(n) { n % 2 == 0 }) -/// True +/// > from_list([1, 2, 5, 7, 9]) |> any(fn(n) { n % 2 == 0 }) +/// True /// -/// > from_list([1, 3, 5, 7, 9]) |> any(fn(n) { n % 2 == 0 }) -/// False +/// > from_list([1, 3, 5, 7, 9]) |> any(fn(n) { n % 2 == 0 }) +/// False +/// ``` /// pub fn any( in iterator: Iterator(element), @@ -865,14 +915,16 @@ fn do_all( /// /// ## Examples /// -/// > empty() |> all(fn(n) { n % 2 == 0 }) -/// True +/// ```gleam +/// > empty() |> all(fn(n) { n % 2 == 0 }) +/// True /// -/// > from_list([2, 4, 6, 8]) |> all(fn(n) { n % 2 == 0 }) -/// True +/// > from_list([2, 4, 6, 8]) |> all(fn(n) { n % 2 == 0 }) +/// True /// -/// > from_list([2, 4, 5, 8]) |> all(fn(n) { n % 2 == 0 }) -/// False +/// > from_list([2, 4, 5, 8]) |> all(fn(n) { n % 2 == 0 }) +/// False +/// ``` /// pub fn all( in iterator: Iterator(element), @@ -907,8 +959,10 @@ fn group_updater( /// /// ## Examples /// -/// > from_list([1, 2, 3, 4, 5, 6]) |> group(by: fn(n) { n % 3 }) -/// map.from_list([#(0, [3, 6]), #(1, [1, 4]), #(2, [2, 5])]) +/// ```gleam +/// > from_list([1, 2, 3, 4, 5, 6]) |> group(by: fn(n) { n % 3 }) +/// map.from_list([#(0, [3, 6]), #(1, [1, 4]), #(2, [2, 5])]) +/// ``` /// pub fn group( in iterator: Iterator(element), @@ -928,11 +982,13 @@ pub fn group( /// /// ## Examples /// -/// > from_list([]) |> reduce(fn(acc, x) { acc + x }) -/// Error(Nil) +/// ```gleam +/// > from_list([]) |> reduce(fn(acc, x) { acc + x }) +/// Error(Nil) /// -/// > from_list([1, 2, 3, 4, 5]) |> reduce(fn(acc, x) { acc + x }) -/// Ok(15) +/// > from_list([1, 2, 3, 4, 5]) |> reduce(fn(acc, x) { acc + x }) +/// Ok(15) +/// ``` /// pub fn reduce( over iterator: Iterator(e), @@ -954,11 +1010,13 @@ pub fn reduce( /// /// ## Examples /// -/// > empty() |> last -/// Error(Nil) +/// ```gleam +/// > empty() |> last +/// Error(Nil) /// -/// > range(1, 10) |> last -/// Ok(9) +/// > range(1, 10) |> last +/// Ok(9) +/// ``` /// pub fn last(iterator: Iterator(element)) -> Result(element, Nil) { iterator @@ -969,8 +1027,10 @@ pub fn last(iterator: Iterator(element)) -> Result(element, Nil) { /// /// ## Examples /// -/// > empty() |> to_list -/// [] +/// ```gleam +/// > empty() |> to_list +/// [] +/// ``` /// pub fn empty() -> Iterator(element) { Iterator(stop) @@ -980,8 +1040,8 @@ pub fn empty() -> Iterator(element) { /// /// ## Examples /// -/// > once(fn() { 1 }) |> to_list -/// [1] +/// > once(fn() { 1 }) |> to_list +/// [1] /// pub fn once(f: fn() -> element) -> Iterator(element) { fn() { Continue(f(), stop) } @@ -992,8 +1052,10 @@ pub fn once(f: fn() -> element) -> Iterator(element) { /// /// ## Examples /// -/// > single(1) |> to_list -/// [1] +/// ```gleam +/// > single(1) |> to_list +/// [1] +/// ``` /// pub fn single(elem: element) -> Iterator(element) { once(fn() { elem }) @@ -1015,11 +1077,13 @@ fn do_interleave( /// /// ## Examples /// -/// > from_list([1, 2, 3, 4]) |> interleave(from_list([11, 12, 13, 14])) |> to_list -/// [1, 11, 2, 12, 3, 13, 4, 14] +/// ```gleam +/// > from_list([1, 2, 3, 4]) |> interleave(from_list([11, 12, 13, 14])) |> to_list +/// [1, 11, 2, 12, 3, 13, 4, 14] /// -/// > from_list([1, 2, 3, 4]) |> interleave(from_list([100])) |> to_list -/// [1, 100, 2, 3, 4] +/// > from_list([1, 2, 3, 4]) |> interleave(from_list([100])) |> to_list +/// [1, 100, 2, 3, 4] +/// ``` /// pub fn interleave( left: Iterator(element), @@ -1053,17 +1117,19 @@ fn do_fold_until( /// /// /// ## Examples -/// > let f = fn(acc, e) { -/// > case e { -/// > _ if e < 4 -> list.Continue(e + acc) -/// > _ -> list.Stop(acc) -/// > } -/// > } -/// > -/// > [1, 2, 3, 4] -/// > |> from_list -/// > |> iterator.fold_until(from: acc, with: f) -/// 6 +/// ```gleam +/// > let f = fn(acc, e) { +/// > case e { +/// > _ if e < 4 -> list.Continue(e + acc) +/// > _ -> list.Stop(acc) +/// > } +/// > } +/// > +/// > [1, 2, 3, 4] +/// > |> from_list +/// > |> iterator.fold_until(from: acc, with: f) +/// 6 +/// ``` /// pub fn fold_until( over iterator: Iterator(e), @@ -1096,16 +1162,18 @@ fn do_try_fold( /// If the returned value is `Error(error)` try_fold will stop and return that error. /// /// ## Examples -/// -/// > [1, 2, 3, 4] -/// > |> iterator.from_list() -/// > |> try_fold(0, fn(acc, i) { -/// > case i < 3 { -/// > True -> Ok(acc + i) -/// > False -> Error(Nil) -/// > } -/// > }) -/// Error(Nil) +/// +/// ```gleam +/// > [1, 2, 3, 4] +/// > |> iterator.from_list() +/// > |> try_fold(0, fn(acc, i) { +/// > case i < 3 { +/// > True -> Ok(acc + i) +/// > False -> Error(Nil) +/// > } +/// > }) +/// Error(Nil) +/// ``` /// pub fn try_fold( over iterator: Iterator(e), diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index c74bd20..ef3a8bc 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -8,14 +8,18 @@ //// //// There is a dedicated syntax for prefixing to a list: //// -//// let new_list = [1, 2, ..existing_list] +//// ```gleam +//// let new_list = [1, 2, ..existing_list] +//// ``` //// //// And a matching syntax for getting the first elements of a list: //// -//// case list { -//// [first_element, ..rest] -> first_element -//// _ -> "this pattern matches when the list is empty" -//// } +//// ```gleam +//// case list { +//// [first_element, ..rest] -> first_element +//// _ -> "this pattern matches when the list is empty" +//// } +//// ``` //// import gleam/int @@ -38,14 +42,16 @@ pub type LengthMismatch { /// /// ## Examples /// -/// > length([]) -/// 0 +/// ```gleam +/// > length([]) +/// 0 /// -/// > length([1]) -/// 1 +/// > length([1]) +/// 1 /// -/// > length([1, 2]) -/// 2 +/// > length([1, 2]) +/// 2 +/// ``` /// pub fn length(of list: List(a)) -> Int { do_length(list) @@ -80,14 +86,16 @@ if javascript { /// /// ## Examples /// -/// > reverse([]) -/// [] +/// ```gleam +/// > reverse([]) +/// [] /// -/// > reverse([1]) -/// [1] +/// > reverse([1]) +/// [1] /// -/// > reverse([1, 2]) -/// [2, 1] +/// > reverse([1, 2]) +/// [2, 1] +/// ``` /// pub fn reverse(xs: List(a)) -> List(a) { do_reverse(xs) @@ -117,14 +125,16 @@ if javascript { /// /// ## Examples /// -/// > is_empty([]) -/// True +/// ```gleam +/// > is_empty([]) +/// True /// -/// > is_empty([1]) -/// False +/// > is_empty([1]) +/// False /// -/// > is_empty([1, 1]) -/// False +/// > is_empty([1, 1]) +/// False +/// ``` /// pub fn is_empty(list: List(a)) -> Bool { list == [] @@ -137,20 +147,22 @@ pub fn is_empty(list: List(a)) -> Bool { /// /// ## Examples /// -/// > [] |> contains(any: 0) -/// False +/// ```gleam +/// > [] |> contains(any: 0) +/// False /// -/// > [0] |> contains(any: 0) -/// True +/// > [0] |> contains(any: 0) +/// True /// -/// > [1] |> contains(any: 0) -/// False +/// > [1] |> contains(any: 0) +/// False /// -/// > [1, 1] |> contains(any: 0) -/// False +/// > [1, 1] |> contains(any: 0) +/// False /// -/// > [1, 0] |> contains(any: 0) -/// True +/// > [1, 0] |> contains(any: 0) +/// True +/// ``` /// pub fn contains(list: List(a), any elem: a) -> Bool { case list { @@ -163,14 +175,16 @@ pub fn contains(list: List(a), any elem: a) -> Bool { /// /// ## Examples /// -/// > first([]) -/// Error(Nil) +/// ```gleam +/// > first([]) +/// Error(Nil) /// -/// > first([0]) -/// Ok(0) +/// > first([0]) +/// Ok(0) /// -/// > first([1, 2]) -/// Ok(1) +/// > first([1, 2]) +/// Ok(1) +/// ``` /// pub fn first(list: List(a)) -> Result(a, Nil) { case list { @@ -186,14 +200,16 @@ pub fn first(list: List(a)) -> Result(a, Nil) { /// /// ## Examples /// -/// > rest([]) -/// Error(Nil) +/// ```gleam +/// > rest([]) +/// Error(Nil) /// -/// > rest([0]) -/// Ok([]) +/// > rest([0]) +/// Ok([]) /// -/// > rest([1, 2]) -/// Ok([2]) +/// > rest([1, 2]) +/// Ok([2]) +/// ``` /// pub fn rest(list: List(a)) -> Result(List(a), Nil) { case list { @@ -220,11 +236,13 @@ fn do_filter(list: List(a), fun: fn(a) -> Bool, acc: List(a)) -> List(a) { /// /// ## Examples /// -/// > filter([2, 4, 6, 1], fn(x) { x > 2 }) -/// [4, 6] +/// ```gleam +/// > filter([2, 4, 6, 1], fn(x) { x > 2 }) +/// [4, 6] /// -/// > filter([2, 4, 6, 1], fn(x) { x > 6 }) -/// [] +/// > filter([2, 4, 6, 1], fn(x) { x > 6 }) +/// [] +/// ``` /// pub fn filter(list: List(a), for predicate: fn(a) -> Bool) -> List(a) { do_filter(list, predicate, []) @@ -252,11 +270,13 @@ fn do_filter_map( /// /// ## Examples /// -/// > filter_map([2, 4, 6, 1], Error) -/// [] +/// ```gleam +/// > filter_map([2, 4, 6, 1], Error) +/// [] /// -/// > filter_map([2, 4, 6, 1], fn(x) { Ok(x + 1) }) -/// [3, 5, 7, 2] +/// > filter_map([2, 4, 6, 1], fn(x) { Ok(x + 1) }) +/// [3, 5, 7, 2] +/// ``` /// pub fn filter_map(list: List(a), with fun: fn(a) -> Result(b, e)) -> List(b) { do_filter_map(list, fun, []) @@ -274,8 +294,8 @@ fn do_map(list: List(a), fun: fn(a) -> b, acc: List(b)) -> List(b) { /// /// ## Examples /// -/// > map([2, 4, 6], fn(x) { x * 2 }) -/// [4, 8, 12] +/// > map([2, 4, 6], fn(x) { x * 2 }) +/// [4, 8, 12] /// pub fn map(list: List(a), with fun: fn(a) -> b) -> List(b) { do_map(list, fun, []) @@ -334,8 +354,10 @@ fn do_index_map( /// /// ## Examples /// -/// > index_map(["a", "b"], fn(i, x) { #(i, x) }) -/// [#(0, "a"), #(1, "b")] +/// ```gleam +/// > index_map(["a", "b"], fn(i, x) { #(i, x) }) +/// [#(0, "a"), #(1, "b")] +/// ``` /// pub fn index_map(list: List(a), with fun: fn(Int, a) -> b) -> List(b) { do_index_map(list, fun, 0, []) @@ -368,17 +390,19 @@ fn do_try_map( /// /// ## Examples /// -/// > try_map([1, 2, 3], fn(x) { Ok(x + 2) }) -/// Ok([3, 4, 5]) +/// ```gleam +/// > try_map([1, 2, 3], fn(x) { Ok(x + 2) }) +/// Ok([3, 4, 5]) /// -/// > try_map([1, 2, 3], fn(_) { Error(0) }) -/// Error(0) +/// > try_map([1, 2, 3], fn(_) { Error(0) }) +/// Error(0) /// -/// > try_map([[1], [2, 3]], head) -/// Ok([1, 2]) +/// > try_map([[1], [2, 3]], head) +/// Ok([1, 2]) /// -/// > try_map([[1], [], [2]], head) -/// Error(Nil) +/// > try_map([[1], [], [2]], head) +/// Error(Nil) +/// ``` /// pub fn try_map( over list: List(a), @@ -397,11 +421,13 @@ pub fn try_map( /// /// ## Examples /// -/// > drop([1, 2, 3, 4], 2) -/// [3, 4] +/// ```gleam +/// > drop([1, 2, 3, 4], 2) +/// [3, 4] /// -/// > drop([1, 2, 3, 4], 9) -/// [] +/// > drop([1, 2, 3, 4], 9) +/// [] +/// ``` /// pub fn drop(from list: List(a), up_to n: Int) -> List(a) { case n <= 0 { @@ -435,11 +461,13 @@ fn do_take(list: List(a), n: Int, acc: List(a)) -> List(a) { /// /// ## Examples /// -/// > take([1, 2, 3, 4], 2) -/// [1, 2] +/// ```gleam +/// > take([1, 2, 3, 4], 2) +/// [1, 2] /// -/// > take([1, 2, 3, 4], 9) -/// [1, 2, 3, 4] +/// > take([1, 2, 3, 4], 9) +/// [1, 2, 3, 4] +/// ``` /// pub fn take(from list: List(a), up_to n: Int) -> List(a) { do_take(list, n, []) @@ -449,8 +477,8 @@ pub fn take(from list: List(a), up_to n: Int) -> List(a) { /// /// ## Examples /// -/// > new() -/// [] +/// > new() +/// [] /// pub fn new() -> List(a) { [] @@ -463,8 +491,10 @@ pub fn new() -> List(a) { /// /// ## Examples /// -/// > append([1, 2], [3]) -/// [1, 2, 3] +/// ```gleam +/// > append([1, 2], [3]) +/// [1, 2, 3] +/// ``` /// pub fn append(first: List(a), second: List(a)) -> List(a) { do_append(first, second) @@ -491,7 +521,9 @@ if javascript { /// Prefixes an item to a list. This can also be done using the dedicated /// syntax instead /// -/// let new_list = [1, ..existing_list] +/// ```gleam +/// let new_list = [1, ..existing_list] +/// ``` /// pub fn prepend(to list: List(a), item: a) -> List(a) { [item, ..list] @@ -511,8 +543,10 @@ fn do_flatten(lists: List(List(a)), acc: List(a)) -> List(a) { /// /// ## Examples /// -/// > flatten([[1], [2, 3], []]) -/// [1, 2, 3] +/// ```gleam +/// > flatten([[1], [2, 3], []]) +/// [1, 2, 3] +/// ``` /// pub fn flatten(lists: List(List(a))) -> List(a) { do_flatten(lists, []) @@ -679,14 +713,16 @@ pub fn fold_until( /// /// ## Examples /// -/// > find([1, 2, 3], fn(x) { x > 2 }) -/// Ok(3) +/// ```gleam +/// > find([1, 2, 3], fn(x) { x > 2 }) +/// Ok(3) /// -/// > find([1, 2, 3], fn(x) { x > 4 }) -/// Error(Nil) +/// > find([1, 2, 3], fn(x) { x > 4 }) +/// Error(Nil) /// -/// > find([], fn(_) { True }) -/// Error(Nil) +/// > find([], fn(_) { True }) +/// Error(Nil) +/// ``` /// pub fn find( in haystack: List(a), @@ -709,14 +745,16 @@ pub fn find( /// /// ## Examples /// -/// > find_map([[], [2], [3]], head) -/// Ok(2) +/// ```gleam +/// > find_map([[], [2], [3]], head) +/// Ok(2) /// -/// > find_map([[], []], head) -/// Error(Nil) +/// > find_map([[], []], head) +/// Error(Nil) /// -/// > find_map([], head) -/// Error(Nil) +/// > find_map([], head) +/// Error(Nil) +/// ``` /// pub fn find_map( in haystack: List(a), @@ -738,14 +776,16 @@ pub fn find_map( /// /// ## Examples /// -/// > all([], fn(x) { x > 3 }) -/// True +/// ```gleam +/// > all([], fn(x) { x > 3 }) +/// True /// -/// > all([4, 5], fn(x) { x > 3 }) -/// True +/// > all([4, 5], fn(x) { x > 3 }) +/// True /// -/// > all([4, 3], fn(x) { x > 3 }) -/// False +/// > all([4, 3], fn(x) { x > 3 }) +/// False +/// ``` /// pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { case list { @@ -760,17 +800,19 @@ pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { /// /// ## Examples /// -/// > any([], fn(x) { x > 3 }) -/// False +/// ```gleam +/// > any([], fn(x) { x > 3 }) +/// False /// -/// > any([4, 5], fn(x) { x > 3 }) -/// True +/// > any([4, 5], fn(x) { x > 3 }) +/// True /// -/// > any([4, 3], fn(x) { x > 4 }) -/// False +/// > any([4, 3], fn(x) { x > 4 }) +/// False /// -/// > any([3, 4], fn(x) { x > 3 }) -/// True +/// > any([3, 4], fn(x) { x > 3 }) +/// True +/// ``` /// pub fn any(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { case list { @@ -793,17 +835,19 @@ fn do_zip(xs: List(a), ys: List(b), acc: List(#(a, b))) -> List(#(a, b)) { /// /// ## Examples /// -/// > zip([], []) -/// [] +/// ```gleam +/// > zip([], []) +/// [] /// -/// > zip([1, 2], [3]) -/// [#(1, 3)] +/// > zip([1, 2], [3]) +/// [#(1, 3)] /// -/// > zip([1], [3, 4]) -/// [#(1, 3)] +/// > zip([1], [3, 4]) +/// [#(1, 3)] /// -/// > zip([1, 2], [3, 4]) -/// [#(1, 3), #(2, 4)] +/// > zip([1, 2], [3, 4]) +/// [#(1, 3), #(2, 4)] +/// ``` /// pub fn zip(xs: List(a), ys: List(b)) -> List(#(a, b)) { do_zip(xs, ys, []) @@ -815,17 +859,19 @@ pub fn zip(xs: List(a), ys: List(b)) -> List(#(a, b)) { /// /// ## Examples /// -/// > strict_zip([], []) -/// Ok([]) +/// ```gleam +/// > strict_zip([], []) +/// Ok([]) /// -/// > strict_zip([1, 2], [3]) -/// Error(LengthMismatch) +/// > strict_zip([1, 2], [3]) +/// Error(LengthMismatch) /// -/// > strict_zip([1], [3, 4]) -/// Error(LengthMismatch) +/// > strict_zip([1], [3, 4]) +/// Error(LengthMismatch) /// -/// > strict_zip([1, 2], [3, 4]) -/// Ok([#(1, 3), #(2, 4)]) +/// > strict_zip([1, 2], [3, 4]) +/// Ok([#(1, 3), #(2, 4)]) +/// ``` /// pub fn strict_zip( l1: List(a), @@ -848,11 +894,13 @@ fn do_unzip(input, xs, ys) { /// /// ## Examples /// -/// > unzip([#(1, 2), #(3, 4)]) -/// #([1, 3], [2, 4]) +/// ```gleam +/// > unzip([#(1, 2), #(3, 4)]) +/// #([1, 3], [2, 4]) /// -/// > unzip([]) -/// #([], []) +/// > unzip([]) +/// #([], []) +/// ``` /// pub fn unzip(input: List(#(a, b))) -> #(List(a), List(b)) { do_unzip(input, [], []) @@ -871,11 +919,13 @@ fn do_intersperse(list: List(a), separator: a, acc: List(a)) -> List(a) { /// /// ## Examples /// -/// > intersperse([1, 1, 1], 2) -/// [1, 2, 1, 2, 1] +/// ```gleam +/// > intersperse([1, 1, 1], 2) +/// [1, 2, 1, 2, 1] /// -/// > intersperse([], 2) -/// [] +/// > intersperse([], 2) +/// [] +/// ``` /// pub fn intersperse(list: List(a), with elem: a) -> List(a) { case list { @@ -893,11 +943,13 @@ pub fn intersperse(list: List(a), with elem: a) -> List(a) { /// /// ## Examples /// -/// > at([1, 2, 3], 1) -/// Ok(2) +/// ```gleam +/// > at([1, 2, 3], 1) +/// Ok(2) /// -/// > at([1, 2, 3], 5) -/// Error(Nil) +/// > at([1, 2, 3], 5) +/// Error(Nil) +/// ``` /// pub fn at(in list: List(a), get index: Int) -> Result(a, Nil) { list @@ -911,8 +963,10 @@ pub fn at(in list: List(a), get index: Int) -> Result(a, Nil) { /// /// ## Examples /// -/// > unique([1, 1, 1, 4, 7, 3, 3, 4]) -/// [1, 4, 7, 3] +/// ```gleam +/// > unique([1, 1, 1, 4, 7, 3, 3, 4]) +/// [1, 4, 7, 3] +/// ``` /// pub fn unique(list: List(a)) -> List(a) { case list { @@ -958,9 +1012,11 @@ fn do_sort( /// /// ## Examples /// -/// > import gleam/int -/// > list.sort([4, 3, 6, 5, 4, 1, 2], by: int.compare) -/// [1, 2, 3, 4, 4, 5, 6] +/// ```gleam +/// > import gleam/int +/// > list.sort([4, 3, 6, 5, 4, 1, 2], by: int.compare) +/// [1, 2, 3, 4, 4, 5, 6] +/// ``` /// pub fn sort(list: List(a), by compare: fn(a, a) -> Order) -> List(a) { do_sort(list, compare, length(list)) @@ -970,14 +1026,16 @@ pub fn sort(list: List(a), by compare: fn(a, a) -> Order) -> List(a) { /// /// ## Examples /// -/// > range(0, 0) -/// [] +/// ```gleam +/// > range(0, 0) +/// [] /// -/// > range(0, 5) -/// [0, 1, 2, 3, 4] +/// > range(0, 5) +/// [0, 1, 2, 3, 4] /// -/// > range(1, -5) -/// [1, 0, -1, -2, -3, -4] +/// > range(1, -5) +/// [1, 0, -1, -2, -3, -4] +/// ``` /// pub fn range(from start: Int, to stop: Int) -> List(Int) { case int.compare(start, stop) { @@ -998,11 +1056,13 @@ fn do_repeat(a: a, times: Int, acc: List(a)) -> List(a) { /// /// ## Examples /// -/// > repeat("a", times: 0) -/// [] +/// ```gleam +/// > repeat("a", times: 0) +/// [] /// -/// > repeat("a", times: 5) -/// ["a", "a", "a", "a", "a"] +/// > repeat("a", times: 5) +/// ["a", "a", "a", "a", "a"] +/// ``` /// pub fn repeat(item a: a, times times: Int) -> List(a) { do_repeat(a, times, []) @@ -1026,14 +1086,16 @@ fn do_split(list: List(a), n: Int, taken: List(a)) -> #(List(a), List(a)) { /// /// ## Examples /// -/// > split([6, 7, 8, 9], 0) -/// #([], [6, 7, 8, 9]) +/// ```gleam +/// > split([6, 7, 8, 9], 0) +/// #([], [6, 7, 8, 9]) /// -/// > split([6, 7, 8, 9], 2) -/// #([6, 7], [8, 9]) +/// > split([6, 7, 8, 9], 2) +/// #([6, 7], [8, 9]) /// -/// > split([6, 7, 8, 9], 4) -/// #([6, 7, 8, 9], []) +/// > split([6, 7, 8, 9], 4) +/// #([6, 7, 8, 9], []) +/// ``` /// pub fn split(list list: List(a), at index: Int) -> #(List(a), List(a)) { do_split(list, index, []) @@ -1062,11 +1124,13 @@ fn do_split_while( /// /// ## Examples /// -/// > split_while([1, 2, 3, 4, 5], fn(x) { x <= 3 }) -/// #([1, 2, 3], [4, 5]) +/// ```gleam +/// > split_while([1, 2, 3, 4, 5], fn(x) { x <= 3 }) +/// #([1, 2, 3], [4, 5]) /// -/// > split_while([1, 2, 3, 4, 5], fn(x) { x <= 5 }) -/// #([1, 2, 3, 4, 5], []) +/// > split_while([1, 2, 3, 4, 5], fn(x) { x <= 5 }) +/// #([1, 2, 3, 4, 5], []) +/// ``` /// pub fn split_while( list list: List(a), @@ -1085,14 +1149,16 @@ pub fn split_while( /// /// ## Examples /// -/// > key_find([#("a", 0), #("b", 1)], "a") -/// Ok(0) +/// ```gleam +/// > key_find([#("a", 0), #("b", 1)], "a") +/// Ok(0) /// -/// > key_find([#("a", 0), #("b", 1)], "b") -/// Ok(1) +/// > key_find([#("a", 0), #("b", 1)], "b") +/// Ok(1) /// -/// > key_find([#("a", 0), #("b", 1)], "c") -/// Error(Nil) +/// > key_find([#("a", 0), #("b", 1)], "c") +/// Error(Nil) +/// ``` /// pub fn key_find( in keyword_list: List(#(k, v)), @@ -1127,14 +1193,16 @@ fn do_pop(haystack, predicate, checked) { /// /// ## Examples /// -/// > pop([1, 2, 3], fn(x) { x > 2 }) -/// Ok(#(3, [1, 2])) +/// ```gleam +/// > pop([1, 2, 3], fn(x) { x > 2 }) +/// Ok(#(3, [1, 2])) /// -/// > pop([1, 2, 3], fn(x) { x > 4 }) -/// Error(Nil) +/// > pop([1, 2, 3], fn(x) { x > 4 }) +/// Error(Nil) /// -/// > pop([], fn(_) { True }) -/// Error(Nil) +/// > pop([], fn(_) { True }) +/// Error(Nil) +/// ``` /// pub fn pop( in haystack: List(a), @@ -1161,14 +1229,16 @@ fn do_pop_map(haystack, mapper, checked) { /// /// ## Examples /// -/// > pop_map([[], [2], [3]], head) -/// Ok(#(2, [[], [3]])) +/// ```gleam +/// > pop_map([[], [2], [3]], head) +/// Ok(#(2, [[], [3]])) /// -/// > pop_map([[], []], head) -/// Error(Nil) +/// > pop_map([[], []], head) +/// Error(Nil) /// -/// > pop_map([], head) -/// Error(Nil) +/// > pop_map([], head) +/// Error(Nil) +/// ``` /// pub fn pop_map( in haystack: List(a), @@ -1185,14 +1255,16 @@ pub fn pop_map( /// /// ## Examples /// -/// > key_pop([#("a", 0), #("b", 1)], "a") -/// Ok(#(0, [#("b", 1)])) +/// ```gleam +/// > key_pop([#("a", 0), #("b", 1)], "a") +/// Ok(#(0, [#("b", 1)])) /// -/// > key_pop([#("a", 0), #("b", 1)], "b") -/// Ok(#(1, [#("a", 0)])) +/// > key_pop([#("a", 0), #("b", 1)], "b") +/// Ok(#(1, [#("a", 0)])) /// -/// > key_pop([#("a", 0), #("b", 1)], "c") -/// Error(Nil) +/// > key_pop([#("a", 0), #("b", 1)], "c") +/// Error(Nil) +/// ``` /// pub fn key_pop( haystack: List(#(k, v)), @@ -1218,11 +1290,13 @@ pub fn key_pop( /// /// ## Examples /// -/// > key_set([#(5, 0), #(4, 1)], 4, 100) -/// [#(5, 0), #(4, 100)] +/// ```gleam +/// > key_set([#(5, 0), #(4, 1)], 4, 100) +/// [#(5, 0), #(4, 100)] /// -/// > key_set([#(5, 0), #(4, 1)], 1, 100) -/// [#(5, 0), #(4, 1), #(1, 100)] +/// > key_set([#(5, 0), #(4, 1)], 1, 100) +/// [#(5, 0), #(4, 1), #(1, 100)] +/// ``` /// pub fn key_set(list: List(#(a, b)), key: a, value: b) -> List(#(a, b)) { case list { @@ -1267,8 +1341,10 @@ pub fn partition( /// /// ## Examples /// -/// > permutations([1, 2]) -/// [[1, 2], [2, 1]] +/// ```gleam +/// > permutations([1, 2]) +/// [[1, 2], [2, 1]] +/// ``` /// pub fn permutations(l: List(a)) -> List(List(a)) { case l { @@ -1332,8 +1408,10 @@ pub fn window_by_2(l: List(a)) -> List(#(a, a)) { /// /// ## Examples /// -/// > drop_while([1, 2, 3, 4], fn (x) { x < 3 }) -/// [3, 4] +/// ```gleam +/// > drop_while([1, 2, 3, 4], fn (x) { x < 3 }) +/// [3, 4] +/// ``` /// pub fn drop_while( in list: List(a), @@ -1368,8 +1446,10 @@ fn do_take_while( /// /// ## Examples /// -/// > take_while([1, 2, 3, 2, 4], fn (x) { x < 3 }) -/// [1, 2] +/// ```gleam +/// > take_while([1, 2, 3, 2, 4], fn (x) { x < 3 }) +/// [1, 2] +/// ``` /// pub fn take_while( in list: List(a), @@ -1405,8 +1485,10 @@ fn do_chunk( /// /// ## Examples /// -/// > [1, 2, 2, 3, 4, 4, 6, 7, 7] |> chunk(by: fn(n) { n % 2 }) -/// [[1], [2, 2], [3], [4, 4, 6], [7, 7]] +/// ```gleam +/// > [1, 2, 2, 3, 4, 4, 6, 7, 7] |> chunk(by: fn(n) { n % 2 }) +/// [[1], [2, 2], [3], [4, 4, 6], [7, 7]] +/// ``` /// pub fn chunk(in list: List(a), by f: fn(a) -> key) -> List(List(a)) { case list { @@ -1447,11 +1529,13 @@ fn do_sized_chunk( /// /// ## Examples /// -/// > [1, 2, 3, 4, 5, 6] |> sized_chunk(into: 2) -/// [[1, 2], [3, 4], [5, 6]] +/// ```gleam +/// > [1, 2, 3, 4, 5, 6] |> sized_chunk(into: 2) +/// [[1, 2], [3, 4], [5, 6]] /// -/// > [1, 2, 3, 4, 5, 6, 7, 8] |> sized_chunk(into: 3) -/// [[1, 2, 3], [4, 5, 6], [7, 8]] +/// > [1, 2, 3, 4, 5, 6, 7, 8] |> sized_chunk(into: 3) +/// [[1, 2, 3], [4, 5, 6], [7, 8]] +/// ``` /// pub fn sized_chunk(in list: List(a), into count: Int) -> List(List(a)) { do_sized_chunk(list, count, count, [], []) @@ -1466,11 +1550,13 @@ pub fn sized_chunk(in list: List(a), into count: Int) -> List(List(a)) { /// /// ## Examples /// -/// > [] |> reduce(fn(acc, x) { acc + x }) -/// Error(Nil) +/// ```gleam +/// > [] |> reduce(fn(acc, x) { acc + x }) +/// Error(Nil) /// -/// > [1, 2, 3, 4, 5] |> reduce(fn(acc, x) { acc + x }) -/// Ok(15) +/// > [1, 2, 3, 4, 5] |> reduce(fn(acc, x) { acc + x }) +/// Ok(15) +/// ``` /// pub fn reduce(over list: List(a), with fun: fn(a, a) -> a) -> Result(a, Nil) { case list { @@ -1498,8 +1584,10 @@ fn do_scan( /// /// ## Examples /// -/// > scan(over: [1, 2, 3], from: 100, with: fn(acc, i) { acc + i }) -/// [101, 103, 106] +/// ```gleam +/// > scan(over: [1, 2, 3], from: 100, with: fn(acc, i) { acc + i }) +/// [101, 103, 106] +/// ``` /// pub fn scan( over list: List(a), @@ -1519,11 +1607,13 @@ pub fn scan( /// /// ## Examples /// -/// > last([]) -/// Error(Nil) +/// > last([]) +/// Error(Nil) /// -/// > last([1, 2, 3, 4, 5]) -/// Ok(5) +/// ```gleam +/// > last([1, 2, 3, 4, 5]) +/// Ok(5) +/// ``` /// pub fn last(list: List(a)) -> Result(a, Nil) { list diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam index 8f8ca12..b801f44 100644 --- a/src/gleam/map.gleam +++ b/src/gleam/map.gleam @@ -24,11 +24,13 @@ pub external type Map(key, value) /// /// ## Examples /// -/// > new() |> size() -/// 0 +/// ```gleam +/// > new() |> size() +/// 0 /// -/// > new() |> insert("key", "value") |> size() -/// 1 +/// > new() |> insert("key", "value") |> size() +/// 1 +/// ``` /// /// pub fn size(map: Map(k, v)) -> Int { @@ -52,11 +54,13 @@ if javascript { /// /// ## Examples /// -/// > new() |> to_list() -/// [] +/// ```gleam +/// > new() |> to_list() +/// [] /// -/// > new() |> insert("key", 0) |> to_list() -/// [#("key", 0)] +/// > new() |> insert("key", 0) |> to_list() +/// [#("key", 0)] +/// ``` /// pub fn to_list(map: Map(key, value)) -> List(#(key, value)) { do_to_list(map) @@ -96,11 +100,13 @@ if javascript { /// /// ## Examples /// -/// > new() |> insert("a", 0) |> has_key("a") -/// True +/// ```gleam +/// > new() |> insert("a", 0) |> has_key("a") +/// True /// -/// > new() |> insert("a", 0) |> has_key("b") -/// False +/// > new() |> insert("a", 0) |> has_key("b") +/// False +/// ``` /// pub fn has_key(map: Map(k, v), key: k) -> Bool { do_has_key(key, map) @@ -140,11 +146,13 @@ if javascript { /// /// ## Examples /// -/// > new() |> insert("a", 0) |> get("a") -/// Ok(0) +/// ```gleam +/// > new() |> insert("a", 0) |> get("a") +/// Ok(0) /// -/// > new() |> insert("a", 0) |> get("b") -/// Error(Nil) +/// > new() |> insert("a", 0) |> get("b") +/// Error(Nil) +/// ``` /// pub fn get(from: Map(key, value), get: key) -> Result(value, Nil) { do_get(from, get) @@ -167,11 +175,13 @@ if javascript { /// /// ## Examples /// -/// > new() |> insert("a", 0) |> to_list -/// [#("a", 0)] +/// ```gleam +/// > new() |> insert("a", 0) |> to_list +/// [#("a", 0)] /// -/// > new() |> insert("a", 0) |> insert("a", 5) |> to_list -/// [#("a", 5)] +/// > new() |> insert("a", 0) |> insert("a", 5) |> to_list +/// [#("a", 5)] +/// ``` /// pub fn insert(into map: Map(k, v), for key: k, insert value: v) -> Map(k, v) { do_insert(key, value, map) @@ -192,10 +202,12 @@ if javascript { /// /// ## Examples /// -/// > [#(3, 3), #(2, 4)] -/// > |> from_list -/// > |> map_values(fn(key, value) { key * value }) -/// [#(3, 9), #(2, 8)] +/// ```gleam +/// > [#(3, 3), #(2, 4)] +/// > |> from_list +/// > |> map_values(fn(key, value) { key * value }) +/// [#(3, 9), #(2, 8)] +/// ``` /// /// pub fn map_values(in map: Map(k, v), with fun: fn(k, v) -> w) -> Map(k, w) { @@ -223,8 +235,10 @@ if javascript { /// /// ## Examples /// -/// > keys([#("a", 0), #("b", 1)]) -/// ["a", "b"] +/// ```gleam +/// > keys([#("a", 0), #("b", 1)]) +/// ["a", "b"] +/// ``` /// pub fn keys(map: Map(keys, v)) -> List(keys) { do_keys(map) @@ -251,8 +265,10 @@ if javascript { /// /// ## Examples /// -/// > keys(from_list([#("a", 0), #("b", 1)])) -/// [0, 1] +/// ```gleam +/// > keys(from_list([#("a", 0), #("b", 1)])) +/// [0, 1] +/// ``` /// pub fn values(map: Map(k, values)) -> List(values) { do_values(map) @@ -276,13 +292,15 @@ if javascript { /// /// ## Examples /// -/// > from_list([#("a", 0), #("b", 1)]) -/// > |> filter(fn(key, value) { value != 0 }) -/// from_list([#("b", 1)]) +/// ```gleam +/// > from_list([#("a", 0), #("b", 1)]) +/// > |> filter(fn(key, value) { value != 0 }) +/// from_list([#("b", 1)]) /// -/// > from_list([#("a", 0), #("b", 1)]) -/// > |> filter(fn(key, value) { True }) -/// from_list([#("a", 0), #("b", 1)]) +/// > from_list([#("a", 0), #("b", 1)]) +/// > |> filter(fn(key, value) { True }) +/// from_list([#("a", 0), #("b", 1)]) +/// ``` /// pub fn filter(in map: Map(k, v), for property: fn(k, v) -> Bool) -> Map(k, v) { do_filter(property, map) @@ -317,13 +335,15 @@ if javascript { /// /// ## Examples /// -/// > from_list([#("a", 0), #("b", 1)]) -/// > |> take(["b"]) -/// from_list([#("b", 1)]) +/// ```gleam +/// > from_list([#("a", 0), #("b", 1)]) +/// > |> take(["b"]) +/// from_list([#("b", 1)]) /// -/// > from_list([#("a", 0), #("b", 1)]) -/// > |> take(["a", "b", "c"]) -/// from_list([#("a", 0), #("b", 1)]) +/// > from_list([#("a", 0), #("b", 1)]) +/// > |> take(["a", "b", "c"]) +/// from_list([#("a", 0), #("b", 1)]) +/// ``` /// pub fn take(from map: Map(k, v), keeping desired_keys: List(k)) -> Map(k, v) { do_take(desired_keys, map) @@ -353,10 +373,12 @@ if javascript { /// /// ## Examples /// -/// > let a = from_list([#("a", 0), #("b", 1)]) -/// > let b = from_list([#("b", 2), #("c", 3)]) -/// > merge(a, b) -/// from_list([#("a", 0), #("b", 2), #("c", 3)]) +/// ```gleam +/// > let a = from_list([#("a", 0), #("b", 1)]) +/// > let b = from_list([#("b", 2), #("c", 3)]) +/// > merge(a, b) +/// from_list([#("a", 0), #("b", 2), #("c", 3)]) +/// ``` /// pub fn merge(into map: Map(k, v), from new_entries: Map(k, v)) -> Map(k, v) { do_merge(map, new_entries) @@ -384,11 +406,13 @@ if javascript { /// /// ## Examples /// -/// > delete([#("a", 0), #("b", 1)], "a") -/// from_list([#("b", 1)]) +/// ```gleam +/// > delete([#("a", 0), #("b", 1)], "a") +/// from_list([#("b", 1)]) /// -/// > delete([#("a", 0), #("b", 1)], "c") -/// from_list([#("a", 0), #("b", 1)]) +/// > delete([#("a", 0), #("b", 1)], "c") +/// from_list([#("a", 0), #("b", 1)]) +/// ``` /// pub fn delete(from map: Map(k, v), delete key: k) -> Map(k, v) { do_delete(key, map) @@ -409,14 +433,16 @@ if javascript { /// /// ## Examples /// -/// > drop([#("a", 0), #("b", 1)], ["a"]) -/// from_list([#("b", 2)]) +/// ```gleam +/// > drop([#("a", 0), #("b", 1)], ["a"]) +/// from_list([#("b", 2)]) /// -/// > delete([#("a", 0), #("b", 1)], ["c"]) -/// from_list([#("a", 0), #("b", 1)]) +/// > delete([#("a", 0), #("b", 1)], ["c"]) +/// from_list([#("a", 0), #("b", 1)]) /// -/// > drop([#("a", 0), #("b", 1)], ["a", "b", "c"]) -/// from_list([]) +/// > drop([#("a", 0), #("b", 1)], ["a", "b", "c"]) +/// from_list([]) +/// ``` /// pub fn drop(from map: Map(k, v), drop disallowed_keys: List(k)) -> Map(k, v) { list.fold(over: disallowed_keys, from: map, with: delete) @@ -429,19 +455,21 @@ pub fn drop(from map: Map(k, v), drop disallowed_keys: List(k)) -> Map(k, v) { /// /// ## Example /// -/// > let increment = fn(x) { -/// > case x { -/// > Some(i) -> i + 1 -/// > None -> 0 -/// > } -/// > } -/// > let map = from_list([#("a", 0)]) -/// > -/// > update(map, "a", increment) -/// from_list([#("a", 1)]) -/// -/// > update(map, "b", increment) -/// from_list([#("a", 0), #("b", 0)]) +/// ```gleam +/// > let increment = fn(x) { +/// > case x { +/// > Some(i) -> i + 1 +/// > None -> 0 +/// > } +/// > } +/// > let map = from_list([#("a", 0)]) +/// > +/// > update(map, "a", increment) +/// from_list([#("a", 1)]) +/// +/// > update(map, "b", increment) +/// from_list([#("a", 0), #("b", 0)]) +/// ``` /// pub fn update( in map: Map(k, v), @@ -471,13 +499,15 @@ fn do_fold(list: List(#(k, v)), initial: acc, fun: fn(acc, k, v) -> acc) -> acc /// /// # Examples /// -/// > let map = from_list([#("a", 1), #("b", 3), #("c", 9)]) -/// > fold(map, 0, fn(accumulator, key, value) { accumulator + value }) -/// 13 +/// ```gleam +/// > let map = from_list([#("a", 1), #("b", 3), #("c", 9)]) +/// > fold(map, 0, fn(accumulator, key, value) { accumulator + value }) +/// 13 /// -/// > import gleam/string.{append} -/// > fold(map, "", fn(accumulator, key, value) { append(accumulator, key) }) -/// "abc" +/// > import gleam/string.{append} +/// > fold(map, "", fn(accumulator, key, value) { append(accumulator, key) }) +/// "abc" +/// ``` /// pub fn fold( over map: Map(k, v), diff --git a/src/gleam/option.gleam b/src/gleam/option.gleam index 4a097e8..8af678f 100644 --- a/src/gleam/option.gleam +++ b/src/gleam/option.gleam @@ -18,11 +18,11 @@ pub type Option(a) { /// ## Examples /// /// ``` -/// > all([Some(1), Some(2)]) -/// Some([1, 2]) +/// > all([Some(1), Some(2)]) +/// Some([1, 2]) /// -/// > all([Some(1), None]) -/// None +/// > all([Some(1), None]) +/// None /// ``` /// pub fn all(list: List(Option(a))) -> Option(List(a)) { @@ -42,11 +42,13 @@ pub fn all(list: List(Option(a))) -> Option(List(a)) { /// /// ## Examples /// -/// > is_some(Some(1)) -/// True +/// ```gleam +/// > is_some(Some(1)) +/// True /// -/// > is_some(None) -/// False +/// > is_some(None) +/// False +/// ``` /// pub fn is_some(option: Option(a)) -> Bool { option != None @@ -56,11 +58,13 @@ pub fn is_some(option: Option(a)) -> Bool { /// /// ## Examples /// -/// > is_none(Some(1)) -/// False +/// ```gleam +/// > is_none(Some(1)) +/// False /// -/// > is_none(None) -/// True +/// > is_none(None) +/// True +/// ``` /// pub fn is_none(option: Option(a)) -> Bool { option == None @@ -70,10 +74,12 @@ pub fn is_none(option: Option(a)) -> Bool { /// /// ## Examples /// -/// > to_result(Some(1), "some_error") -/// Ok(1) -/// > to_result(None, "some_error") -/// Error("some_error") +/// ```gleam +/// > to_result(Some(1), "some_error") +/// Ok(1) +/// > to_result(None, "some_error") +/// Error("some_error") +/// ``` /// pub fn to_result(option: Option(a), e) -> Result(a, e) { case option { @@ -86,10 +92,12 @@ pub fn to_result(option: Option(a), e) -> Result(a, e) { /// /// ## Examples /// -/// > from_result(Ok(1)) -/// Some(1) -/// > from_result(Error("some_error")) -/// None +/// ```gleam +/// > from_result(Ok(1)) +/// Some(1) +/// > from_result(Error("some_error")) +/// None +/// ``` /// pub fn from_result(result: Result(a, e)) -> Option(a) { case result { @@ -102,11 +110,13 @@ pub fn from_result(result: Result(a, e)) -> Option(a) { /// /// ## Examples /// -/// > unwrap(Some(1), 0) -/// 1 +/// ```gleam +/// > unwrap(Some(1), 0) +/// 1 /// -/// > unwrap(None, 0) -/// 0 +/// > unwrap(None, 0) +/// 0 +/// ``` /// pub fn unwrap(option: Option(a), or default: a) -> a { case option { @@ -119,11 +129,13 @@ pub fn unwrap(option: Option(a), or default: a) -> a { /// /// ## Examples /// -/// > lazy_unwrap(Some(1), fn() { 0 }) -/// 1 +/// ```gleam +/// > lazy_unwrap(Some(1), fn() { 0 }) +/// 1 /// -/// > lazy_unwrap(None, fn() { 0 }) -/// 0 +/// > lazy_unwrap(None, fn() { 0 }) +/// 0 +/// ``` /// pub fn lazy_unwrap(option: Option(a), or default: fn() -> a) -> a { case option { @@ -140,11 +152,13 @@ pub fn lazy_unwrap(option: Option(a), or default: fn() -> a) -> a { /// /// ## Examples /// -/// > map(over: Some(1), with: fn(x) { x + 1 }) -/// Some(2) +/// ```gleam +/// > map(over: Some(1), with: fn(x) { x + 1 }) +/// Some(2) /// -/// > map(over: None, with: fn(x) { x + 1 }) -/// None +/// > map(over: None, with: fn(x) { x + 1 }) +/// None +/// ``` /// pub fn map(over option: Option(a), with fun: fn(a) -> b) -> Option(b) { case option { @@ -157,14 +171,16 @@ pub fn map(over option: Option(a), with fun: fn(a) -> b) -> Option(b) { /// /// ## Examples /// -/// > flatten(Some(Some(1))) -/// Some(1) +/// ```gleam +/// > flatten(Some(Some(1))) +/// Some(1) /// -/// > flatten(Some(None)) -/// None +/// > flatten(Some(None)) +/// None /// -/// > flatten(None) -/// None +/// > flatten(None) +/// None +/// ``` /// pub fn flatten(option: Option(Option(a))) -> Option(a) { case option { @@ -185,17 +201,19 @@ pub fn flatten(option: Option(Option(a))) -> Option(a) { /// /// ## Examples /// -/// > then(Some(1), fn(x) { Some(x + 1) }) -/// Some(2) +/// ```gleam +/// > then(Some(1), fn(x) { Some(x + 1) }) +/// Some(2) /// -/// > then(Some(1), fn(x) { Some(#("a", x)) }) -/// Some(#("a", 1)) +/// > then(Some(1), fn(x) { Some(#("a", x)) }) +/// Some(#("a", 1)) /// -/// > then(Some(1), fn(_) { None }) -/// None +/// > then(Some(1), fn(_) { None }) +/// None /// -/// > then(None, fn(x) { Some(x + 1) }) -/// None +/// > then(None, fn(x) { Some(x + 1) }) +/// None +/// ``` /// pub fn then(option: Option(a), apply fun: fn(a) -> Option(b)) -> Option(b) { case option { @@ -208,17 +226,19 @@ pub fn then(option: Option(a), apply fun: fn(a) -> Option(b)) -> Option(b) { /// /// ## Examples /// -/// > or(Some(1), Some(2)) -/// Some(1) +/// ```gleam +/// > or(Some(1), Some(2)) +/// Some(1) /// -/// > or(Some(1), None) -/// Some(1) +/// > or(Some(1), None) +/// Some(1) /// -/// > or(None, Some(2)) -/// Some(2) +/// > or(None, Some(2)) +/// Some(2) /// -/// > or(None, None) -/// None +/// > or(None, None) +/// None +/// ``` /// pub fn or(first: Option(a), second: Option(a)) -> Option(a) { case first { @@ -231,17 +251,19 @@ pub fn or(first: Option(a), second: Option(a)) -> Option(a) { /// /// ## Examples /// -/// > lazy_or(Some(1), fn() { Some(2) }) -/// Some(1) +/// ```gleam +/// > lazy_or(Some(1), fn() { Some(2) }) +/// Some(1) /// -/// > lazy_or(Some(1), fn() { None }) -/// Some(1) +/// > lazy_or(Some(1), fn() { None }) +/// Some(1) /// -/// > lazy_or(None, fn() { Some(2) }) -/// Some(2) +/// > lazy_or(None, fn() { Some(2) }) +/// Some(2) /// -/// > lazy_or(None, fn() { None }) -/// None +/// > lazy_or(None, fn() { None }) +/// None +/// ``` /// pub fn lazy_or(first: Option(a), second: fn() -> Option(a)) -> Option(a) { case first { diff --git a/src/gleam/order.gleam b/src/gleam/order.gleam index 9b75384..9595bf8 100644 --- a/src/gleam/order.gleam +++ b/src/gleam/order.gleam @@ -17,14 +17,16 @@ pub type Order { /// /// ## Examples /// -/// > reverse(Lt) -/// Gt +/// ```gleam +/// > reverse(Lt) +/// Gt /// -/// > reverse(Eq) -/// Eq +/// > reverse(Eq) +/// Eq /// -/// > reverse(Lt) -/// Gt +/// > reverse(Lt) +/// Gt +/// ``` /// pub fn reverse(order: Order) -> Order { case order { @@ -38,14 +40,16 @@ pub fn reverse(order: Order) -> Order { /// /// ## Examples /// -/// > to_int(Lt) -/// -1 +/// ```gleam +/// > to_int(Lt) +/// -1 /// -/// > to_int(Eq) -/// 0 +/// > to_int(Eq) +/// 0 /// -/// > to_int(Gt) -/// 1 +/// > to_int(Gt) +/// 1 +/// ``` /// pub fn to_int(order: Order) -> Int { case order { @@ -59,8 +63,10 @@ pub fn to_int(order: Order) -> Int { /// /// ## Examples /// -/// > compare(Eq, with: Lt) -/// Gt +/// ```gleam +/// > compare(Eq, with: Lt) +/// Gt +/// ``` /// pub fn compare(a: Order, with b: Order) -> Order { case a, b { @@ -74,8 +80,10 @@ pub fn compare(a: Order, with b: Order) -> Order { /// /// ## Examples /// -/// > max(Eq, Lt) -/// Eq +/// ```gleam +/// > max(Eq, Lt) +/// Eq +/// ``` /// pub fn max(a: Order, b: Order) -> Order { case a, b { @@ -89,8 +97,10 @@ pub fn max(a: Order, b: Order) -> Order { /// /// ## Examples /// -/// > min(Eq, Lt) -/// Lt +/// ```gleam +/// > min(Eq, Lt) +/// Lt +/// ``` /// pub fn min(a: Order, b: Order) -> Order { case a, b { diff --git a/src/gleam/pair.gleam b/src/gleam/pair.gleam index 0770e92..e9b99fd 100644 --- a/src/gleam/pair.gleam +++ b/src/gleam/pair.gleam @@ -2,8 +2,10 @@ /// /// ## Examples /// -/// > first(#(1, 2)) -/// 1 +/// ```gleam +/// > first(#(1, 2)) +/// 1 +/// ``` /// pub fn first(pair: #(a, b)) -> a { let #(a, _) = pair @@ -14,8 +16,10 @@ pub fn first(pair: #(a, b)) -> a { /// /// ## Examples /// -/// > second(#(1, 2)) -/// 2 +/// ```gleam +/// > second(#(1, 2)) +/// 2 +/// ``` /// pub fn second(pair: #(a, b)) -> b { let #(_, a) = pair @@ -26,8 +30,10 @@ pub fn second(pair: #(a, b)) -> b { /// /// ## Examples /// -/// > swap(#(1, 2)) -/// #(2, 1) +/// ```gleam +/// > swap(#(1, 2)) +/// #(2, 1) +/// ``` /// pub fn swap(pair: #(a, b)) -> #(b, a) { let #(a, b) = pair @@ -39,8 +45,10 @@ pub fn swap(pair: #(a, b)) -> #(b, a) { /// /// ## Examples /// -/// > #(1, 2) |> map_first(fn(n) { n * 2 }) -/// #(2, 2) +/// ```gleam +/// > #(1, 2) |> map_first(fn(n) { n * 2 }) +/// #(2, 2) +/// ``` /// pub fn map_first(of pair: #(a, b), with fun: fn(a) -> c) -> #(c, b) { let #(a, b) = pair @@ -52,8 +60,10 @@ pub fn map_first(of pair: #(a, b), with fun: fn(a) -> c) -> #(c, b) { /// /// ## Examples /// -/// > #(1, 2) |> map_second(fn(n) { n * 2 }) -/// #(1, 4) +/// ```gleam +/// > #(1, 2) |> map_second(fn(n) { n * 2 }) +/// #(1, 4) +/// ``` /// pub fn map_second(of pair: #(a, b), with fun: fn(b) -> c) -> #(a, c) { let #(a, b) = pair diff --git a/src/gleam/queue.gleam b/src/gleam/queue.gleam index 0deaa07..039a43a 100644 --- a/src/gleam/queue.gleam +++ b/src/gleam/queue.gleam @@ -30,8 +30,10 @@ pub fn new() -> Queue(a) { /// /// # Examples /// -/// > [1, 2, 3] |> from_list |> length -/// 3 +/// ```gleam +/// > [1, 2, 3] |> from_list |> length +/// 3 +/// ``` /// pub fn from_list(list: List(a)) -> Queue(a) { Queue(in: [], out: list) @@ -44,8 +46,10 @@ pub fn from_list(list: List(a)) -> Queue(a) { /// /// # Examples /// -/// > new() |> push_back(1) |> push_back(2) |> to_list -/// [1, 2] +/// ```gleam +/// > new() |> push_back(1) |> push_back(2) |> to_list +/// [1, 2] +/// ``` /// pub fn to_list(queue: Queue(a)) -> List(a) { queue.out @@ -58,14 +62,16 @@ pub fn to_list(queue: Queue(a)) -> List(a) { /// /// ## Examples /// -/// > [] |> from_list |> is_empty -/// True +/// ```gleam +/// > [] |> from_list |> is_empty +/// True /// -/// > [1] |> from_list |> is_empty -/// False +/// > [1] |> from_list |> is_empty +/// False /// -/// > [1, 2] |> from_list |> is_empty -/// False +/// > [1, 2] |> from_list |> is_empty +/// False +/// ``` /// pub fn is_empty(queue: Queue(a)) -> Bool { queue.in == [] && queue.out == [] @@ -78,14 +84,16 @@ pub fn is_empty(queue: Queue(a)) -> Bool { /// /// ## Examples /// -/// > length(from_list([])) -/// 0 +/// ```gleam +/// > length(from_list([])) +/// 0 /// -/// > length(from_list([1])) -/// 1 +/// > length(from_list([1])) +/// 1 /// -/// > length(from_list([1, 2])) -/// 2 +/// > length(from_list([1, 2])) +/// 2 +/// ``` /// pub fn length(queue: Queue(a)) -> Int { list.length(queue.in) + list.length(queue.out) @@ -95,8 +103,10 @@ pub fn length(queue: Queue(a)) -> Int { /// /// # Examples /// -/// > [1, 2] |> from_list |> push_back(3) |> to_list -/// [1, 2, 3] +/// ```gleam +/// > [1, 2] |> from_list |> push_back(3) |> to_list +/// [1, 2, 3] +/// ``` /// pub fn push_back(onto queue: Queue(a), this item: a) -> Queue(a) { Queue(in: [item, ..queue.in], out: queue.out) @@ -106,8 +116,10 @@ pub fn push_back(onto queue: Queue(a), this item: a) -> Queue(a) { /// /// # Examples /// -/// > [0, 0] |> from_list |> push_front(1) |> to_list -/// [1, 0, 0] +/// ```gleam +/// > [0, 0] |> from_list |> push_front(1) |> to_list +/// [1, 0, 0] +/// ``` /// pub fn push_front(onto queue: Queue(a), this item: a) -> Queue(a) { Queue(in: queue.in, out: [item, ..queue.out]) @@ -121,20 +133,22 @@ pub fn push_front(onto queue: Queue(a), this item: a) -> Queue(a) { /// /// # Examples /// -/// > queue.new() -/// > |> queue.push_back(0) -/// > |> queue.push_back(1) -/// > |> queue.pop_back() -/// Ok(#(1, queue.push_front(queue.new(), 0))) +/// ```gleam +/// > queue.new() +/// > |> queue.push_back(0) +/// > |> queue.push_back(1) +/// > |> queue.pop_back() +/// Ok(#(1, queue.push_front(queue.new(), 0))) /// -/// > queue.new() -/// > |> queue.push_front(0) -/// > |> queue.pop_back() -/// Ok(#(0, queue.new())) +/// > queue.new() +/// > |> queue.push_front(0) +/// > |> queue.pop_back() +/// Ok(#(0, queue.new())) /// -/// > queue.new() -/// > |> queue.pop_back() -/// Error(Nil) +/// > queue.new() +/// > |> queue.pop_back() +/// Error(Nil) +/// ``` /// pub fn pop_back(from queue: Queue(a)) -> Result(#(a, Queue(a)), Nil) { case queue { @@ -155,20 +169,22 @@ pub fn pop_back(from queue: Queue(a)) -> Result(#(a, Queue(a)), Nil) { /// /// # Examples /// -/// > queue.new() -/// > |> queue.push_front(1) -/// > |> queue.push_front(0) -/// > |> queue.pop_front() -/// Ok(#(0, queue.push_back(queue.new(), 1))) +/// ```gleam +/// > queue.new() +/// > |> queue.push_front(1) +/// > |> queue.push_front(0) +/// > |> queue.pop_front() +/// Ok(#(0, queue.push_back(queue.new(), 1))) /// -/// > queue.new() -/// > |> queue.push_back(0) -/// > |> queue.pop_front() -/// Ok(#(0, queue.new())) +/// > queue.new() +/// > |> queue.push_back(0) +/// > |> queue.pop_front() +/// Ok(#(0, queue.new())) /// -/// > queue.new() -/// > |> queue.pop_back() -/// Error(Nil) +/// > queue.new() +/// > |> queue.pop_back() +/// Error(Nil) +/// ``` /// pub fn pop_front(from queue: Queue(a)) -> Result(#(a, Queue(a)), Nil) { case queue { @@ -188,14 +204,16 @@ pub fn pop_front(from queue: Queue(a)) -> Result(#(a, Queue(a)), Nil) { /// /// ## Examples /// -/// > [] |> from_list |> reverse |> to_list -/// [] +/// ```gleam +/// > [] |> from_list |> reverse |> to_list +/// [] /// -/// > [1] |> from_list |> reverse |> to_list -/// [1] +/// > [1] |> from_list |> reverse |> to_list +/// [1] /// -/// > [1, 2] |> from_list |> reverse |> to_list -/// [2, 1] +/// > [1, 2] |> from_list |> reverse |> to_list +/// [2, 1] +/// ``` /// pub fn reverse(queue: Queue(a)) -> Queue(a) { Queue(in: queue.out, out: queue.in) diff --git a/src/gleam/regex.gleam b/src/gleam/regex.gleam index 79c6620..a0fbd08 100644 --- a/src/gleam/regex.gleam +++ b/src/gleam/regex.gleam @@ -38,15 +38,17 @@ pub type Options { /// /// ## Examples /// -/// > let options = Options(case_insensitive: False, multi_line: True) -/// > assert Ok(re) = compile("^[0-9]", with: options) -/// > match(re, "abc\n123") -/// True -/// -/// > let options = Options(case_insensitive: True, multi_line: False) -/// > assert Ok(re) = compile("[A-Z]", with: options) -/// > match(re, "abc123") -/// True +/// ```gleam +/// > let options = Options(case_insensitive: False, multi_line: True) +/// > assert Ok(re) = compile("^[0-9]", with: options) +/// > match(re, "abc\n123") +/// True +/// +/// > let options = Options(case_insensitive: True, multi_line: False) +/// > assert Ok(re) = compile("[A-Z]", with: options) +/// > match(re, "abc123") +/// True +/// ``` /// pub fn compile( pattern: String, @@ -69,20 +71,22 @@ if javascript { /// /// ## Examples /// -/// > assert Ok(re) = from_string("[0-9]") -/// > match(re, "abc123") -/// True +/// ```gleam +/// > assert Ok(re) = from_string("[0-9]") +/// > match(re, "abc123") +/// True /// -/// > match(re, "abcxyz") -/// False +/// > match(re, "abcxyz") +/// False /// -/// > from_string("[0-9") -/// Error( -/// CompileError( -/// error: "missing terminating ] for character class", -/// byte_index: 4 -/// ) -/// ) +/// > from_string("[0-9") +/// Error( +/// CompileError( +/// error: "missing terminating ] for character class", +/// byte_index: 4 +/// ) +/// ) +/// ``` /// pub fn from_string(pattern: String) -> Result(Regex, CompileError) { compile(pattern, Options(case_insensitive: False, multi_line: False)) @@ -92,12 +96,14 @@ pub fn from_string(pattern: String) -> Result(Regex, CompileError) { /// /// ## Examples /// -/// > assert Ok(re) = from_string("^f.o.?") -/// > check(with: re, content: "foo") -/// True +/// ```gleam +/// > assert Ok(re) = from_string("^f.o.?") +/// > check(with: re, content: "foo") +/// True /// -/// > check(with: re, content: "boo") -/// False +/// > check(with: re, content: "boo") +/// False +/// ``` /// pub fn check(with regex: Regex, content content: String) -> Bool { do_check(regex, content) @@ -117,9 +123,11 @@ if javascript { /// /// ## Examples /// -/// > assert Ok(re) = from_string(" *, *") -/// > split(with: re, content: "foo,32, 4, 9 ,0") -/// ["foo", "32", "4", "9", "0"] +/// ```gleam +/// > assert Ok(re) = from_string(" *, *") +/// > split(with: re, content: "foo,32, 4, 9 ,0") +/// ["foo", "32", "4", "9", "0"] +/// ``` /// pub fn split(with regex: Regex, content string: String) -> List(String) { do_split(regex, string) @@ -143,18 +151,20 @@ if javascript { /// /// ## Examples /// -/// > assert Ok(re) = regex.from_string("[oi]n a (\\w+)") -/// > regex.scan(with: re, content: "I am on a boat in a lake.") -/// [ -/// Match( -/// content: "on a boat", -/// submatches: [Some("boat")] -/// ), -/// Match( -/// content: "in a lake", -/// submatches: [Some("lake")] -/// ) -/// ] +/// ```gleam +/// > assert Ok(re) = regex.from_string("[oi]n a (\\w+)") +/// > regex.scan(with: re, content: "I am on a boat in a lake.") +/// [ +/// Match( +/// content: "on a boat", +/// submatches: [Some("boat")] +/// ), +/// Match( +/// content: "in a lake", +/// submatches: [Some("lake")] +/// ) +/// ] +/// ``` /// pub fn scan(with regex: Regex, content string: String) -> List(Match) { do_scan(regex, string) diff --git a/src/gleam/result.gleam b/src/gleam/result.gleam index 96d55c6..150de35 100644 --- a/src/gleam/result.gleam +++ b/src/gleam/result.gleam @@ -7,11 +7,13 @@ import gleam/list /// /// ## Examples /// -/// > is_ok(Ok(1)) -/// True +/// ```gleam +/// > is_ok(Ok(1)) +/// True /// -/// > is_ok(Error(Nil)) -/// False +/// > is_ok(Error(Nil)) +/// False +/// ``` /// pub fn is_ok(result: Result(a, e)) -> Bool { case result { @@ -24,11 +26,13 @@ pub fn is_ok(result: Result(a, e)) -> Bool { /// /// ## Examples /// -/// > is_error(Ok(1)) -/// False +/// ```gleam +/// > is_error(Ok(1)) +/// False /// -/// > is_error(Error(Nil)) -/// True +/// > is_error(Error(Nil)) +/// True +/// ``` /// pub fn is_error(result: Result(a, e)) -> Bool { case result { @@ -45,11 +49,13 @@ pub fn is_error(result: Result(a, e)) -> Bool { /// /// ## Examples /// -/// > map(over: Ok(1), with: fn(x) { x + 1 }) -/// Ok(2) +/// ```gleam +/// > map(over: Ok(1), with: fn(x) { x + 1 }) +/// Ok(2) /// -/// > map(over: Error(1), with: fn(x) { x + 1 }) -/// Error(1) +/// > 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) { case result { @@ -66,11 +72,13 @@ pub fn map(over result: Result(a, e), with fun: fn(a) -> b) -> Result(b, e) { /// /// ## Examples /// -/// > map_error(over: Error(1), with: fn(x) { x + 1 }) -/// Error(2) +/// ```gleam +/// > map_error(over: Error(1), with: fn(x) { x + 1 }) +/// Error(2) /// -/// > map_error(over: Ok(1), with: fn(x) { x + 1 }) -/// Ok(1) +/// > map_error(over: Ok(1), with: fn(x) { x + 1 }) +/// Ok(1) +/// ``` /// pub fn map_error( over result: Result(a, e), @@ -86,14 +94,16 @@ pub fn map_error( /// /// ## Examples /// -/// > flatten(Ok(Ok(1))) -/// Ok(1) +/// ```gleam +/// > flatten(Ok(Ok(1))) +/// Ok(1) /// -/// > flatten(Ok(Error(""))) -/// Error("") +/// > flatten(Ok(Error(""))) +/// Error("") /// -/// > flatten(Error(Nil)) -/// Error(Nil) +/// > flatten(Error(Nil)) +/// Error(Nil) +/// ``` /// pub fn flatten(result: Result(Result(a, e), e)) -> Result(a, e) { case result { @@ -114,17 +124,19 @@ pub fn flatten(result: Result(Result(a, e), e)) -> Result(a, e) { /// /// ## Examples /// -/// > then(Ok(1), fn(x) { Ok(x + 1) }) -/// Ok(2) +/// ```gleam +/// > then(Ok(1), fn(x) { Ok(x + 1) }) +/// Ok(2) /// -/// > then(Ok(1), fn(x) { Ok(#("a", x)) }) -/// Ok(#("a", 1)) +/// > then(Ok(1), fn(x) { Ok(#("a", x)) }) +/// Ok(#("a", 1)) /// -/// > then(Ok(1), fn(_) { Error("Oh no") }) -/// Error("Oh no") +/// > then(Ok(1), fn(_) { Error("Oh no") }) +/// Error("Oh no") /// -/// > then(Error(Nil), fn(x) { Ok(x + 1) }) -/// Error(Nil) +/// > then(Error(Nil), fn(x) { Ok(x + 1) }) +/// Error(Nil) +/// ``` /// pub fn then( result: Result(a, e), @@ -228,11 +240,13 @@ pub fn unwrap_both(result: Result(a, a)) -> a { /// /// ## Examples /// -/// > nil_error(Error(1)) -/// Error(Nil) +/// ```gleam +/// > nil_error(Error(1)) +/// Error(Nil) /// -/// > nil_error(Ok(1)) -/// Ok(1) +/// > nil_error(Ok(1)) +/// Ok(1) +/// ``` /// pub fn nil_error(result: Result(a, e)) -> Result(a, Nil) { map_error(result, fn(_) { Nil }) @@ -242,17 +256,19 @@ pub fn nil_error(result: Result(a, e)) -> Result(a, Nil) { /// /// ## Examples /// -/// > or(Ok(1), Ok(2)) -/// Ok(1) +/// ```gleam +/// > or(Ok(1), Ok(2)) +/// Ok(1) /// -/// > or(Ok(1), Error("Error 2")) -/// Ok(1) +/// > or(Ok(1), Error("Error 2")) +/// Ok(1) /// -/// > or(Error("Error 1"), Ok(2)) -/// Ok(2) +/// > or(Error("Error 1"), Ok(2)) +/// Ok(2) /// -/// > or(Error("Error 1"), Error("Error 2")) -/// Error("Error 2") +/// > or(Error("Error 1"), Error("Error 2")) +/// Error("Error 2") +/// ``` /// pub fn or(first: Result(a, e), second: Result(a, e)) -> Result(a, e) { case first { @@ -265,17 +281,19 @@ pub fn or(first: Result(a, e), second: Result(a, e)) -> Result(a, e) { /// /// ## Examples /// -/// > lazy_or(Ok(1), fn() { Ok(2) }) -/// Ok(1) +/// ```gleam +/// > lazy_or(Ok(1), fn() { Ok(2) }) +/// Ok(1) /// -/// > lazy_or(Ok(1), fn() { Error("Error 2") }) -/// Ok(1) +/// > lazy_or(Ok(1), fn() { Error("Error 2") }) +/// Ok(1) /// -/// > lazy_or(Error("Error 1"), fn() { Ok(2) }) -/// Ok(2) +/// > lazy_or(Error("Error 1"), fn() { Ok(2) }) +/// Ok(2) /// -/// > lazy_or(Error("Error 1"), fn() { Error("Error 2") }) -/// Error("Error 2") +/// > lazy_or(Error("Error 1"), fn() { Error("Error 2") }) +/// Error("Error 2") +/// ``` /// pub fn lazy_or( first: Result(a, e), diff --git a/src/gleam/set.gleam b/src/gleam/set.gleam index 632c951..6821189 100644 --- a/src/gleam/set.gleam +++ b/src/gleam/set.gleam @@ -39,8 +39,10 @@ pub fn new() -> Set(member) { /// /// ## Examples /// -/// > new() |> insert(1) |> insert(2) |> size -/// 2 +/// ```gleam +/// > new() |> insert(1) |> insert(2) |> size +/// 2 +/// ``` /// pub fn size(set: Set(member)) -> Int { map.size(set.map) @@ -52,8 +54,10 @@ pub fn size(set: Set(member)) -> Int { /// /// ## Examples /// -/// > new() |> insert(1) |> insert(2) |> size -/// 2 +/// ```gleam +/// > new() |> insert(1) |> insert(2) |> size +/// 2 +/// ``` /// pub fn insert(into set: Set(member), this member: member) -> Set(member) { Set(map: map.insert(set.map, member, token)) @@ -65,11 +69,13 @@ pub fn insert(into set: Set(member), this member: member) -> Set(member) { /// /// ## Examples /// -/// > new() |> insert(2) |> contains(2) -/// True +/// ```gleam +/// > new() |> insert(2) |> contains(2) +/// True /// -/// > new() |> insert(2) |> contains(1) -/// False +/// > new() |> insert(2) |> contains(1) +/// False +/// ``` /// pub fn contains(in set: Set(member), this member: member) -> Bool { set.map @@ -84,8 +90,10 @@ pub fn contains(in set: Set(member), this member: member) -> Bool { /// /// ## Examples /// -/// > new() |> insert(2) |> delete(2) |> contains(1) -/// False +/// ```gleam +/// > new() |> insert(2) |> delete(2) |> contains(1) +/// False +/// ``` /// pub fn delete(from set: Set(member), this member: member) -> Set(member) { Set(map: map.delete(set.map, member)) @@ -100,8 +108,10 @@ pub fn delete(from set: Set(member), this member: member) -> Set(member) { /// /// ## Examples /// -/// > new() |> insert(2) |> to_list -/// [2] +/// ```gleam +/// > new() |> insert(2) |> to_list +/// [2] +/// ``` /// pub fn to_list(set: Set(member)) -> List(member) { map.keys(set.map) @@ -113,9 +123,11 @@ pub fn to_list(set: Set(member)) -> List(member) { /// /// ## Examples /// -/// > import gleam/list -/// > [1, 1, 2, 4, 3, 2] |> from_list |> to_list |> list.sort -/// [1, 3, 3, 4] +/// ```gleam +/// > import gleam/list +/// > [1, 1, 2, 4, 3, 2] |> from_list |> to_list |> list.sort +/// [1, 3, 3, 4] +/// ``` /// pub fn from_list(members: List(member)) -> Set(member) { let map = @@ -136,9 +148,11 @@ pub fn from_list(members: List(member)) -> Set(member) { /// /// # Examples /// -/// > from_list([1, 3, 9]) -/// > |> fold(0, fn(member, accumulator) { accumulator + member }) -/// 13 +/// ```gleam +/// > from_list([1, 3, 9]) +/// > |> fold(0, fn(member, accumulator) { accumulator + member }) +/// 13 +/// ``` /// pub fn fold( over set: Set(member), @@ -155,11 +169,13 @@ pub fn fold( /// /// ## Examples /// -/// > import gleam/int -/// > from_list([1, 4, 6, 3, 675, 44, 67]) -/// > |> filter(for: int.is_even) -/// > |> to_list -/// [4, 6, 44] +/// ```gleam +/// > import gleam/int +/// > from_list([1, 4, 6, 3, 675, 44, 67]) +/// > |> filter(for: int.is_even) +/// > |> to_list +/// [4, 6, 44] +/// ``` /// pub fn filter( in set: Set(member), @@ -175,8 +191,10 @@ pub fn filter( /// /// ## Examples /// -/// > from_list([1, 2, 3]) |> take([1, 3, 5]) |> to_list -/// [1, 3] +/// ```gleam +/// > from_list([1, 2, 3]) |> take([1, 3, 5]) |> to_list +/// [1, 3] +/// ``` /// pub fn take(from set: Set(member), keeping desired: List(member)) -> Set(member) { Set(map.take(from: set.map, keeping: desired)) @@ -195,8 +213,10 @@ fn order(first: Set(member), second: Set(member)) -> #(Set(member), Set(member)) /// /// ## Examples /// -/// > union(from_list([1, 2]), from_list([2, 3])) |> to_list -/// [1, 2, 3] +/// ```gleam +/// > union(from_list([1, 2]), from_list([2, 3])) |> to_list +/// [1, 2, 3] +/// ``` /// pub fn union(of first: Set(member), and second: Set(member)) -> Set(member) { let #(larger, smaller) = order(first, second) @@ -209,8 +229,10 @@ pub fn union(of first: Set(member), and second: Set(member)) -> Set(member) { /// /// ## Examples /// -/// > intersection(from_list([1, 2]), from_list([2, 3])) |> to_list -/// [2] +/// ```gleam +/// > intersection(from_list([1, 2]), from_list([2, 3])) |> to_list +/// [2] +/// ``` /// pub fn intersection( of first: Set(member), diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 889d2fc..8ff8fcd 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -16,11 +16,13 @@ if erlang { /// /// ## Examples /// -/// > is_empty("") -/// True +/// ```gleam +/// > is_empty("") +/// True /// -/// > is_empty("the world") -/// False +/// > is_empty("the world") +/// False +/// ``` /// pub fn is_empty(str: String) -> Bool { str == "" @@ -33,14 +35,16 @@ pub fn is_empty(str: String) -> Bool { /// /// ## Examples /// -/// > length("Gleam") -/// 5 +/// ```gleam +/// > length("Gleam") +/// 5 /// -/// > length("ß↑e̊") -/// 3 +/// > length("ß↑e̊") +/// 3 /// -/// > length("") -/// 0 +/// > length("") +/// 0 +/// ``` /// pub fn length(string: String) -> Int { do_length(string) @@ -63,8 +67,10 @@ if javascript { /// /// ## Examples /// -/// > reverse("stressed") -/// "desserts" +/// ```gleam +/// > reverse("stressed") +/// "desserts" +/// ``` /// pub fn reverse(string: String) -> String { string @@ -77,11 +83,13 @@ pub fn reverse(string: String) -> String { /// /// ## Examples /// -/// > replace("www.example.com", each: ".", with: "-") -/// "www-example-com" +/// ```gleam +/// > replace("www.example.com", each: ".", with: "-") +/// "www-example-com" /// -/// > replace("a,b,c,d,e", each: ",", with: "/") -/// "a/b/c/d/e" +/// > replace("a,b,c,d,e", each: ",", with: "/") +/// "a/b/c/d/e" +/// ``` /// pub fn replace( in string: String, @@ -101,8 +109,10 @@ pub fn replace( /// /// ## Examples /// -/// > lowercase("X-FILES") -/// "x-files" +/// ```gleam +/// > lowercase("X-FILES") +/// "x-files" +/// ``` /// pub fn lowercase(string: String) -> String { do_lowercase(string) @@ -125,8 +135,10 @@ if javascript { /// /// ## Examples /// -/// > uppercase("skinner") -/// "SKINNER" +/// ```gleam +/// > uppercase("skinner") +/// "SKINNER" +/// ``` /// pub fn uppercase(string: String) -> String { do_uppercase(string) @@ -148,11 +160,13 @@ if javascript { /// /// ## Examples /// -/// > compare("Anthony", "Anthony") -/// order.Eq +/// ```gleam +/// > compare("Anthony", "Anthony") +/// order.Eq /// -/// > compare("A", "B") -/// order.Lt +/// > compare("A", "B") +/// order.Lt +/// ``` /// pub fn compare(a: String, b: String) -> order.Order { case a == b { @@ -179,20 +193,22 @@ if javascript { /// are taken starting from the *end* of the list. /// /// ## Examples -/// > slice(from: "gleam", at_index: 1, length: 2) -/// "le" +/// ```gleam +/// > slice(from: "gleam", at_index: 1, length: 2) +/// "le" /// -/// > slice(from: "gleam", at_index: 1, length: 10) -/// "leam" +/// > slice(from: "gleam", at_index: 1, length: 10) +/// "leam" /// -/// > slice(from: "gleam", at_index: 10, length: 3) -/// "" +/// > slice(from: "gleam", at_index: 10, length: 3) +/// "" /// -/// > slice(from: "gleam", at_index: -2, length: 2) -/// "am" +/// > slice(from: "gleam", at_index: -2, length: 2) +/// "am" /// -/// > slice(from: "gleam", at_index: -12, length: 2) -/// "" +/// > slice(from: "gleam", at_index: -12, length: 2) +/// "" +/// ``` /// pub fn slice(from string: String, at_index idx: Int, length len: Int) -> String { case len < 0 { @@ -225,8 +241,10 @@ if javascript { /// If the `from` string does not contain the `before` string, `from` is returned unchanged. /// /// ## Examples -/// > crop(from: "The Lone Gunmen", before: "Lone") -/// "Lone Gunmen" +/// ```gleam +/// > crop(from: "The Lone Gunmen", before: "Lone") +/// "Lone Gunmen" +/// ``` /// pub fn crop(from string: String, before substring: String) -> String { do_crop(string, substring) @@ -252,8 +270,10 @@ if javascript { /// Drops *n* graphemes from the left side of a `String`. /// /// ## Examples -/// > drop_left(from: "The Lone Gunmen", up_to: 2) -/// "e Lone Gunmen" +/// ```gleam +/// > 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 { case num_graphemes < 0 { @@ -265,8 +285,10 @@ pub fn drop_left(from string: String, up_to num_graphemes: Int) -> String { /// Drops *n* graphemes from the right side of a `String`. /// /// ## Examples -/// > drop_right(from: "Cigarette Smoking Man", up_to: 2) -/// "Cigarette Smoking M" +/// ```gleam +/// > drop_right(from: "Cigarette Smoking Man", up_to: 2) +/// "Cigarette Smoking M" +/// ``` /// pub fn drop_right(from string: String, up_to num_graphemes: Int) -> String { case num_graphemes < 0 { @@ -279,14 +301,16 @@ pub fn drop_right(from string: String, up_to num_graphemes: Int) -> String { /// /// ## Examples /// -/// > contains(does: "theory", contain: "ory") -/// True +/// ```gleam +/// > contains(does: "theory", contain: "ory") +/// True /// -/// > contains(does: "theory", contain: "the") -/// True +/// > contains(does: "theory", contain: "the") +/// True /// -/// > contains(does: "theory", contain: "THE") -/// False +/// > contains(does: "theory", contain: "THE") +/// False +/// ``` /// pub fn contains(does haystack: String, contain needle: String) -> Bool { do_contains(haystack, needle) @@ -314,8 +338,10 @@ if javascript { /// /// ## Examples /// -/// > starts_with("theory", "ory") -/// False +/// ```gleam +/// > starts_with("theory", "ory") +/// False +/// ``` /// pub fn starts_with(string: String, prefix: String) -> Bool { do_starts_with(string, prefix) @@ -335,8 +361,10 @@ if javascript { /// /// ## Examples /// -/// > ends_with("theory", "ory") -/// True +/// ```gleam +/// > ends_with("theory", "ory") +/// True +/// ``` /// pub fn ends_with(string: String, suffix: String) -> Bool { do_ends_with(string, suffix) @@ -356,8 +384,10 @@ if javascript { /// /// ## Examples /// -/// > split("home/gleam/desktop/", on: "/") -/// ["home", "gleam", "desktop", ""] +/// ```gleam +/// > split("home/gleam/desktop/", on: "/") +/// ["home", "gleam", "desktop", ""] +/// ``` /// pub fn split(x: String, on substring: String) -> List(String) { x @@ -372,11 +402,13 @@ pub fn split(x: String, on substring: String) -> List(String) { /// /// ## Examples /// -/// > split_once("home/gleam/desktop/", on: "/") -/// Ok(#("home", "gleam/desktop/")) +/// ```gleam +/// > split_once("home/gleam/desktop/", on: "/") +/// Ok(#("home", "gleam/desktop/")) /// -/// > split_once("home/gleam/desktop/", on: "?") -/// Error(Nil) +/// > split_once("home/gleam/desktop/", on: "?") +/// Error(Nil) +/// ``` /// pub fn split_once( x: String, @@ -416,8 +448,10 @@ if javascript { /// /// ## Examples /// -/// > append(to: "butter", suffix: "fly") -/// "butterfly" +/// ```gleam +/// > append(to: "butter", suffix: "fly") +/// "butterfly" +/// ``` /// pub fn append(to first: String, suffix second: String) -> String { first @@ -434,8 +468,10 @@ pub fn append(to first: String, suffix second: String) -> String { /// /// ## Examples /// -/// > concat(["never", "the", "less"]) -/// "nevertheless" +/// ```gleam +/// > concat(["never", "the", "less"]) +/// "nevertheless" +/// ``` /// pub fn concat(strings: List(String)) -> String { strings @@ -449,8 +485,10 @@ pub fn concat(strings: List(String)) -> String { /// /// ## Examples /// -/// > repeat("ha", times: 3) -/// "hahaha" +/// ```gleam +/// > repeat("ha", times: 3) +/// "hahaha" +/// ``` /// pub fn repeat(string: String, times times: Int) -> String { iterator.repeat(string) @@ -465,8 +503,10 @@ pub fn repeat(string: String, times times: Int) -> String { /// /// ## Examples /// -/// > join(["home","evan","Desktop"], with: "/") -/// "home/evan/Desktop" +/// ```gleam +/// > join(["home","evan","Desktop"], with: "/") +/// "home/evan/Desktop" +/// ``` /// pub fn join(strings: List(String), with separator: String) -> String { strings @@ -478,14 +518,16 @@ pub fn join(strings: List(String), with separator: String) -> String { /// /// ## Examples /// -/// > pad_left("121", to: 5, with: ".") -/// "..121" +/// ```gleam +/// > pad_left("121", to: 5, with: ".") +/// "..121" /// -/// > pad_left("121", to: 3, with: ".") -/// "121" +/// > pad_left("121", to: 3, with: ".") +/// "121" /// -/// > pad_left("121", to: 2, with: ".") -/// "121" +/// > pad_left("121", to: 2, with: ".") +/// "121" +/// ``` /// pub fn pad_left(string: String, to desired_length: Int, with pad_string: String) { let current_length = length(string) @@ -500,14 +542,16 @@ pub fn pad_left(string: String, to desired_length: Int, with pad_string: String) /// /// ## Examples /// -/// > pad_right("121", to: 5, with: ".") -/// "121.." +/// ```gleam +/// > pad_right("121", to: 5, with: ".") +/// "121.." /// -/// > pad_right("121", to: 3, with: ".") -/// "121" +/// > pad_right("121", to: 3, with: ".") +/// "121" /// -/// > pad_right("121", to: 2, with: ".") -/// "121" +/// > pad_right("121", to: 2, with: ".") +/// "121" +/// ``` /// pub fn pad_right( string: String, @@ -535,8 +579,10 @@ fn padding(size: Int, pad_string: String) -> Iterator(String) { /// /// ## Examples /// -/// > trim(" hats \n") -/// "hats" +/// ```gleam +/// > trim(" hats \n") +/// "hats" +/// ``` /// pub fn trim(string: String) -> String { do_trim(string) @@ -566,8 +612,10 @@ if javascript { /// /// ## Examples /// -/// > trim_left(" hats \n") -/// "hats \n" +/// ```gleam +/// > trim_left(" hats \n") +/// "hats \n" +/// ``` /// pub fn trim_left(string: String) -> String { do_trim_left(string) @@ -588,8 +636,10 @@ if javascript { /// /// ## Examples /// -/// > trim_right(" hats \n") -/// " hats" +/// ```gleam +/// > trim_right(" hats \n") +/// " hats" +/// ``` /// pub fn trim_right(string: String) -> String { do_trim_right(string) @@ -610,11 +660,13 @@ if javascript { /// pattern match on `String`s exactly as you would with lists. /// /// ## Examples -/// > pop_grapheme("gleam") -/// Ok(#("g", "leam")) +/// ```gleam +/// > pop_grapheme("gleam") +/// Ok(#("g", "leam")) /// -/// > pop_grapheme("") -/// Error(Nil) +/// > pop_grapheme("") +/// Error(Nil) +/// ``` /// pub fn pop_grapheme(string: String) -> Result(#(String, String), Nil) { do_pop_grapheme(string) @@ -632,8 +684,10 @@ if javascript { /// Converts a `String` to a list of graphemes. /// -/// > to_graphemes("abc") -/// ["a", "b", "c"] +/// ```gleam +/// > to_graphemes("abc") +/// ["a", "b", "c"] +/// ``` /// pub fn to_graphemes(string: String) -> List(String) { case pop_grapheme(string) { diff --git a/src/gleam/string_builder.gleam b/src/gleam/string_builder.gleam index 26b7697..5e0054c 100644 --- a/src/gleam/string_builder.gleam +++ b/src/gleam/string_builder.gleam @@ -295,11 +295,13 @@ if javascript { /// /// ## Examples /// -/// > from_strings(["a", "b"]) == from_string("ab") -/// False +/// ```gleam +/// > from_strings(["a", "b"]) == from_string("ab") +/// False /// -/// > is_equal(from_strings(["a", "b"]), from_string("ab")) -/// True +/// > is_equal(from_strings(["a", "b"]), from_string("ab")) +/// True +/// ``` /// /// pub fn is_equal(a: StringBuilder, b: StringBuilder) -> Bool { @@ -320,14 +322,16 @@ if javascript { /// /// ## Examples /// -/// > from_string("ok") |> is_empty -/// False +/// ```gleam +/// > from_string("ok") |> is_empty +/// False /// -/// > from_string("") |> is_empty -/// True +/// > from_string("") |> is_empty +/// True /// -/// > from_strings([]) |> is_empty -/// True +/// > from_strings([]) |> is_empty +/// True +/// ``` /// /// pub fn is_empty(builder: StringBuilder) -> Bool { |