Skip to content

Commit 0a9d01d

Browse files
committed
Alter example doc syntax, more list docs
1 parent 66eeb70 commit 0a9d01d

File tree

12 files changed

+735
-310
lines changed

12 files changed

+735
-310
lines changed

src/gleam/atom.gleam

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ pub type FromStringError {
2828
///
2929
/// ## Examples
3030
///
31-
/// ```
32-
/// from_string("ok") == Ok(create_from_string("ok"))
33-
/// from_string("some_new_atom") == Error(AtomNotLoaded)
34-
/// ```
31+
/// > from_string("ok")
32+
/// Ok(create_from_string("ok"))
33+
///
34+
/// > from_string("some_new_atom")
35+
/// Error(AtomNotLoaded)
36+
///
3537
///
3638
pub external fn from_string(String) -> Result(Atom, FromStringError) =
3739
"gleam_stdlib" "atom_from_string";
@@ -53,10 +55,9 @@ pub external fn create_from_string(String) -> Atom =
5355
///
5456
/// ## Examples
5557
///
56-
/// ```
57-
/// let ok_atom = create_from_string("ok")
58-
/// to_string(ok_atom) == "ok"
59-
/// ```
58+
/// > let ok_atom = create_from_string("ok")
59+
/// > to_string(ok_atom)
60+
/// "ok"
6061
///
6162
pub external fn to_string(Atom) -> String =
6263
"gleam_stdlib" "atom_to_string";

src/gleam/bool.gleam

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ pub type Bool =
1414
/// Returns the opposite Bool value
1515
///
1616
/// ## Examples
17-
/// ```gleam
18-
/// negate(True) == False
19-
/// ```
17+
/// > negate(True)
18+
/// False
19+
///
2020
///
2121
pub fn negate(bool: Bool) -> Bool {
2222
case bool {
@@ -28,10 +28,10 @@ pub fn negate(bool: Bool) -> Bool {
2828
/// Compares two bools and returns the first values Order to the second.
2929
///
3030
/// ## Examples
31-
/// ```gleam
3231
/// import gleam/order
33-
/// compare(True, False) == order.Gt
34-
/// ```
32+
/// > compare(True, False)
33+
/// order.Gt
34+
///
3535
///
3636
pub fn compare(a: Bool, b: Bool) -> Order {
3737
case a, b {
@@ -45,11 +45,15 @@ pub fn compare(a: Bool, b: Bool) -> Order {
4545
/// Returns `True` if either Bool value is `True`.
4646
///
4747
/// ## Examples
48-
/// ```gleam
49-
/// max(True, False) == True
50-
/// max(False, True) === True
51-
/// max(False, False) === False
52-
/// ```
48+
/// > max(True, False)
49+
/// True
50+
///
51+
/// > max(False, True)
52+
/// True
53+
///
54+
/// > max(False, False)
55+
/// False
56+
///
5357
///
5458
pub fn max(a: Bool, b: Bool) -> Bool {
5559
case a {
@@ -61,11 +65,15 @@ pub fn max(a: Bool, b: Bool) -> Bool {
6165
/// Returns `False` if either Bool value is `False`.
6266
///
6367
/// ## Examples
64-
/// ```gleam
65-
/// max(True, False) == False
66-
/// max(False, True) === False
67-
/// max(False, False) === False
68-
/// ```
68+
/// > max(True, False)
69+
/// False
70+
///
71+
/// > max(False, True)
72+
/// False
73+
///
74+
/// > max(False, False)
75+
/// False
76+
///
6977
///
7078
pub fn min(a: Bool, b: Bool) -> Bool {
7179
case a {
@@ -77,10 +85,12 @@ pub fn min(a: Bool, b: Bool) -> Bool {
7785
/// Returns a numeric representation of the value:
7886
///
7987
/// ## Examples
80-
/// ```gleam
81-
/// to_int(True) == 1
82-
/// to_int(False) == 0
83-
/// ```
88+
/// > to_int(True)
89+
/// 1
90+
///
91+
/// > to_int(False)
92+
/// 0
93+
///
8494
///
8595
pub fn to_int(bool: Bool) -> Int {
8696
case bool {

src/gleam/dynamic.gleam

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,75 @@ pub external fn unsafe_coerce(a) -> b = "gleam_stdlib" "identity";
2121
/// Safely cast a Dynamic value into a String.
2222
///
2323
/// ## Examples
24-
/// ```gleam
25-
/// string(from("Hello")) == Ok("Hello")
26-
/// string(from(123)) == Error("Expected a String, got `123`")
27-
/// ```
24+
/// > string(from("Hello"))
25+
/// Ok("Hello")
26+
///
27+
/// > string(from(123))
28+
/// Error("Expected a String, got `123`")
29+
///
2830
pub external fn string(from: Dynamic) -> Result(String, String)
2931
= "gleam_stdlib" "decode_string"
3032

3133
/// Safely cast a Dynamic value into a String.
3234
///
3335
/// ## Examples
34-
/// ```gleam
35-
/// int(from(123)) == Ok(123)
36-
/// int(from("Hello")) == Error("Expected an Int, got `\"Hello World\"`")
37-
/// ```
36+
/// > int(from(123))
37+
/// Ok(123)
38+
///
39+
/// > int(from("Hello"))
40+
/// Error("Expected an Int, got `\"Hello World\"`")
41+
///
3842
pub external fn int(from: Dynamic) -> Result(Int, String)
3943
= "gleam_stdlib" "decode_int"
4044

4145
/// Safely cast a Dynamic value into a Float.
4246
///
4347
/// ## Examples
44-
/// ```gleam
45-
/// float(from(2.0)) == Ok(2.0)
46-
/// float(from(123)) == Error("Expected a Float, got `123`")
47-
/// ```
48+
/// > float(from(2.0))
49+
/// Ok(2.0)
50+
///
51+
/// > float(from(123))
52+
/// Error("Expected a Float, got `123`")
53+
///
4854
pub external fn float(from: Dynamic) -> Result(Float, String)
4955
= "gleam_stdlib" "decode_float"
5056

5157
/// Safely cast a Dynamic value into an Atom.
5258
///
5359
/// ## Examples
54-
/// ```gleam
5560
/// import gleam/atom
56-
/// atom(from(atom.create_from_string("hello"))) == OK("hello")
57-
/// atom(from(123)) == Error("Expected an Atom, got `123`")
58-
/// ```
61+
/// > atom(from(atom.create_from_string("hello")))
62+
/// OK("hello")
63+
///
64+
/// > atom(from(123))
65+
/// Error("Expected an Atom, got `123`")
66+
///
5967
pub external fn atom(from: Dynamic) -> Result(atom.Atom, String)
6068
= "gleam_stdlib" "decode_atom"
6169

6270
/// Safely cast a Dynamic value into a Bool.
6371
///
6472
/// ## Examples
65-
/// ```gleam
66-
/// bool(from(True)) == Ok(True)
67-
/// bool(from(123)) == Error("Expected a Bool, got `123`")
68-
/// ```
73+
/// > bool(from(True))
74+
/// Ok(True)
75+
///
76+
/// > bool(from(123))
77+
/// Error("Expected a Bool, got `123`")
78+
///
6979
pub external fn bool(from: Dynamic) -> Result(Bool, String)
7080
= "gleam_stdlib" "decode_bool"
7181

7282
/// Safely cast a Dynamic value into a String.
7383
///
7484
/// ## Examples
75-
/// ```gleam
7685
/// import gleam/result
7786
/// let f = fn() { 1 }
78-
/// thunk(from(f)) |> result.is_ok == True
79-
/// thunk(from(123)) == Error("Expected a zero arity function, got `123`")
80-
/// ```
87+
/// > thunk(from(f)) |> result.is_ok
88+
/// True
89+
///
90+
/// > thunk(from(123))
91+
/// Error("Expected a zero arity function, got `123`")
92+
///
8193
pub external fn thunk(from: Dynamic) -> Result(fn() -> Dynamic, String)
8294
= "gleam_stdlib" "decode_thunk"
8395

@@ -87,10 +99,12 @@ external fn list_dynamic(from: Dynamic) -> Result(List(Dynamic), String)
8799
/// Safely cast a Dynamic value into a List of some type.
88100
///
89101
/// ## Examples
90-
/// ```gleam
91-
/// list(from(["a", "b", "c"]), string) == Ok(["a", "b", "c"])
92-
/// list(from([1, 2, 3]), string) == Error("Expected a List, got `[1, 2, 3]`")
93-
/// ```
102+
/// > list(from(["a", "b", "c"]), string)
103+
/// Ok(["a", "b", "c"])
104+
///
105+
/// > list(from([1, 2, 3]), string)
106+
/// Error("Expected a List, got `[1, 2, 3]`")
107+
///
94108
pub fn list(
95109
from dynamic: Dynamic,
96110
containing decoder_type: fn(Dynamic) -> Result(inner, String),
@@ -104,20 +118,24 @@ pub fn list(
104118
/// This will not succeed on a record.
105119
///
106120
/// ## Examples
107-
/// ```gleam
108121
/// import gleam/map
109-
/// field(from(map.new("Hello", "World")), "Hello") == Ok(Dynamic)
110-
/// field(from(123)) == Error("Expected a map with key `\"Hello\"`, got `123`")
111-
/// ```
122+
/// > field(from(map.new("Hello", "World")), "Hello")
123+
/// Ok(Dynamic)
124+
///
125+
/// > field(from(123))
126+
/// Error("Expected a map with key `\"Hello\"`, got `123`")
127+
///
112128
pub external fn field(from: Dynamic, named: a) -> Result(Dynamic, String)
113129
= "gleam_stdlib" "decode_field"
114130

115131
/// Returns an element of a Dynamic value representing a tuple if it exists.
116132
///
117133
/// ## Examples
118-
/// ```gleam
119-
/// element(from(tuple(1, 2)), 0) == Ok(Dynamic)
120-
/// element(from(tuple(1, 2)), 2) == Error("Element position is out-of-bounds")
121-
/// ```
134+
/// > element(from(tuple(1, 2)), 0)
135+
/// Ok(Dynamic)
136+
///
137+
/// > element(from(tuple(1, 2)), 2)
138+
/// Error("Element position is out-of-bounds")
139+
///
122140
pub external fn element(from: Dynamic, position: Int) -> Result(Dynamic, String)
123141
= "gleam_stdlib" "decode_element"

src/gleam/float.gleam

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ pub type Float =
88
/// Attempts to parse the String as a Float if possible
99
///
1010
/// ## Examples
11-
/// ```gleam
12-
/// parse("2.3") == Some(2.3)
13-
/// parse("ABC") == None
14-
/// ```
11+
/// > parse("2.3")
12+
/// Some(2.3)
13+
///
14+
/// > parse("ABC")
15+
/// None
16+
///
1517
///
1618
pub external fn parse(String) -> Option(Float)
1719
= "gleam_stdlib" "parse_float";
@@ -20,9 +22,9 @@ pub external fn parse(String) -> Option(Float)
2022
/// `Float` value
2123
///
2224
/// ## Examples
23-
/// ```gleam
24-
/// to_string(2.3) == "2.3"
25-
/// ```
25+
/// > to_string(2.3)
26+
/// "2.3"
27+
///
2628
///
2729
pub fn to_string(f: Float) -> String {
2830
f
@@ -34,9 +36,9 @@ pub fn to_string(f: Float) -> String {
3436
/// Compares two `Floats`, returning an `Order`
3537
///
3638
/// ## Examples
37-
/// ```gleam
38-
/// compare(2.0, 2.3) == Lt
39-
/// ```
39+
/// > compare(2.0, 2.3)
40+
/// Lt
41+
///
4042
///
4143
pub fn compare(a: Float, b: Float) -> Order {
4244
case a == b {
@@ -52,9 +54,9 @@ pub fn compare(a: Float, b: Float) -> Order {
5254
/// Compares two `Floats`, returning the smaller of the two
5355
///
5456
/// ## Examples
55-
/// ```gleam
56-
/// min(2.0, 2.3) == 2.0
57-
/// ```
57+
/// > min(2.0, 2.3)
58+
/// 2.0
59+
///
5860
///
5961
pub fn min(a: Float, b: Float) -> Float {
6062
case a <. b {
@@ -66,9 +68,9 @@ pub fn min(a: Float, b: Float) -> Float {
6668
/// Compares two `Floats`, returning the larger of the two
6769
///
6870
/// ## Examples
69-
/// ```gleam
70-
/// max(2.0, 2.3) == 2.3
71-
/// ```
71+
/// > max(2.0, 2.3)
72+
/// 2.3
73+
///
7274
///
7375
pub fn max(a: Float, b: Float) -> Float {
7476
case a >. b {
@@ -80,36 +82,38 @@ pub fn max(a: Float, b: Float) -> Float {
8082
/// Rounds the value to the next highest whole number as a Float
8183
///
8284
/// ## Examples
83-
/// ```gleam
84-
/// ceiling(2.3) == 3.0
85-
/// ```
85+
/// > ceiling(2.3)
86+
/// 3.0
87+
///
8688
///
8789
pub external fn ceiling(Float) -> Float = "math" "ceil";
8890

8991
/// Rounds the value to the next lowest whole number as a Float
9092
///
9193
/// ## Examples
92-
/// ```gleam
93-
/// floor(2.3) == 2.0
94-
/// ```
94+
/// > floor(2.3)
95+
/// 2.0
96+
///
9597
///
9698
pub external fn floor(Float) -> Float = "math" "floor";
9799

98100
/// Rounds the value to the nearest whole number as an Int
99101
///
100102
/// ## Examples
101-
/// ```gleam
102-
/// round(2.3) == 2
103-
/// round(2.5) == 3
104-
/// ```
103+
/// > round(2.3)
104+
/// 2
105+
///
106+
/// > round(2.5)
107+
/// 3
108+
///
105109
///
106110
pub external fn round(Float) -> Int = "erlang" "round";
107111

108112
/// Returns the value as an Int, truncating all decimal digits.
109113
///
110114
/// ## Examples
111-
/// ```gleam
112-
/// truncate(2.4343434847383438) == 2
113-
/// ```
115+
/// > truncate(2.4343434847383438)
116+
/// 2
117+
///
114118
///
115119
pub external fn truncate(Float) -> Int = "erlang" "trunc";

0 commit comments

Comments
 (0)