Skip to content

Commit 2ac9811

Browse files
authored
Merge pull request #27 from gleam-community/refactor/remove-let-annotations
♻️ Remove type annotations from let bindings and lambdas.
2 parents 6d5241e + d649063 commit 2ac9811

10 files changed

+443
-467
lines changed

src/gleam_community/maths/arithmetics.gleam

+52-54
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
////<style>
2121
//// .katex { font-size: 1.1em; }
2222
////</style>
23-
////
23+
////
2424
//// ---
25-
////
25+
////
2626
//// Arithmetics: A module containing a collection of fundamental mathematical functions relating to simple arithmetics (addition, subtraction, multiplication, etc.), but also number theory.
27-
////
27+
////
2828
//// * **Division functions**
2929
//// * [`gcd`](#gcd)
3030
//// * [`lcm`](#lcm)
@@ -40,7 +40,7 @@
4040
//// * [`int_cumulative_sum`](#int_cumulative_sum)
4141
//// * [`float_cumulative_product`](#float_cumulative_product)
4242
//// * [`int_cumulative_product`](#int_cumulative_product)
43-
////
43+
////
4444

4545
import gleam/int
4646
import gleam/list
@@ -57,7 +57,7 @@ import gleam_community/maths/piecewise
5757
/// </a>
5858
/// </div>
5959
///
60-
/// The function calculates the greatest common divisor of two integers
60+
/// The function calculates the greatest common divisor of two integers
6161
/// \\(x, y \in \mathbb{Z}\\). The greatest common divisor is the largest positive
6262
/// integer that is divisible by both \\(x\\) and \\(y\\).
6363
///
@@ -70,7 +70,7 @@ import gleam_community/maths/piecewise
7070
/// pub fn example() {
7171
/// arithmetics.gcd(1, 1)
7272
/// |> should.equal(1)
73-
///
73+
///
7474
/// arithmetics.gcd(100, 10)
7575
/// |> should.equal(10)
7676
///
@@ -86,8 +86,8 @@ import gleam_community/maths/piecewise
8686
/// </div>
8787
///
8888
pub fn gcd(x: Int, y: Int) -> Int {
89-
let absx: Int = piecewise.int_absolute_value(x)
90-
let absy: Int = piecewise.int_absolute_value(y)
89+
let absx = piecewise.int_absolute_value(x)
90+
let absy = piecewise.int_absolute_value(y)
9191
do_gcd(absx, absy)
9292
}
9393

@@ -107,24 +107,24 @@ fn do_gcd(x: Int, y: Int) -> Int {
107107
/// </a>
108108
/// </div>
109109
///
110-
///
110+
///
111111
/// Given two integers, \\(x\\) (dividend) and \\(y\\) (divisor), the Euclidean modulo
112-
/// of \\(x\\) by \\(y\\), denoted as \\(x \mod y\\), is the remainder \\(r\\) of the
112+
/// of \\(x\\) by \\(y\\), denoted as \\(x \mod y\\), is the remainder \\(r\\) of the
113113
/// division of \\(x\\) by \\(y\\), such that:
114-
///
114+
///
115115
/// \\[
116116
/// x = q \cdot y + r \quad \text{and} \quad 0 \leq r < |y|,
117117
/// \\]
118-
///
118+
///
119119
/// where \\(q\\) is an integer that represents the quotient of the division.
120120
///
121-
/// The Euclidean modulo function of two numbers, is the remainder operation most
122-
/// commonly utilized in mathematics. This differs from the standard truncating
123-
/// modulo operation frequently employed in programming via the `%` operator.
124-
/// Unlike the `%` operator, which may return negative results depending on the
125-
/// divisor's sign, the Euclidean modulo function is designed to always yield a
121+
/// The Euclidean modulo function of two numbers, is the remainder operation most
122+
/// commonly utilized in mathematics. This differs from the standard truncating
123+
/// modulo operation frequently employed in programming via the `%` operator.
124+
/// Unlike the `%` operator, which may return negative results depending on the
125+
/// divisor's sign, the Euclidean modulo function is designed to always yield a
126126
/// positive outcome, ensuring consistency with mathematical conventions.
127-
///
127+
///
128128
/// Note that like the Gleam division operator `/` this will return `0` if one of
129129
/// the arguments is `0`.
130130
///
@@ -138,7 +138,7 @@ fn do_gcd(x: Int, y: Int) -> Int {
138138
/// pub fn example() {
139139
/// arithmetics.euclidean_modulo(15, 4)
140140
/// |> should.equal(3)
141-
///
141+
///
142142
/// arithmetics.euclidean_modulo(-3, -2)
143143
/// |> should.equal(1)
144144
///
@@ -168,7 +168,7 @@ pub fn int_euclidean_modulo(x: Int, y: Int) -> Int {
168168
/// </a>
169169
/// </div>
170170
///
171-
/// The function calculates the least common multiple of two integers
171+
/// The function calculates the least common multiple of two integers
172172
/// \\(x, y \in \mathbb{Z}\\). The least common multiple is the smallest positive
173173
/// integer that has both \\(x\\) and \\(y\\) as factors.
174174
///
@@ -181,7 +181,7 @@ pub fn int_euclidean_modulo(x: Int, y: Int) -> Int {
181181
/// pub fn example() {
182182
/// arithmetics.lcm(1, 1)
183183
/// |> should.equal(1)
184-
///
184+
///
185185
/// arithmetics.lcm(100, 10)
186186
/// |> should.equal(100)
187187
///
@@ -197,8 +197,8 @@ pub fn int_euclidean_modulo(x: Int, y: Int) -> Int {
197197
/// </div>
198198
///
199199
pub fn lcm(x: Int, y: Int) -> Int {
200-
let absx: Int = piecewise.int_absolute_value(x)
201-
let absy: Int = piecewise.int_absolute_value(y)
200+
let absx = piecewise.int_absolute_value(x)
201+
let absy = piecewise.int_absolute_value(y)
202202
absx * absy / do_gcd(absx, absy)
203203
}
204204

@@ -208,7 +208,7 @@ pub fn lcm(x: Int, y: Int) -> Int {
208208
/// </a>
209209
/// </div>
210210
///
211-
/// The function returns all the positive divisors of an integer, including the
211+
/// The function returns all the positive divisors of an integer, including the
212212
/// number itself.
213213
///
214214
/// <details>
@@ -240,11 +240,11 @@ pub fn divisors(n: Int) -> List(Int) {
240240
}
241241

242242
fn find_divisors(n: Int) -> List(Int) {
243-
let nabs: Float = piecewise.float_absolute_value(conversion.int_to_float(n))
243+
let nabs = piecewise.float_absolute_value(conversion.int_to_float(n))
244244
let assert Ok(sqrt_result) = elementary.square_root(nabs)
245-
let max: Int = conversion.float_to_int(sqrt_result) + 1
245+
let max = conversion.float_to_int(sqrt_result) + 1
246246
list.range(2, max)
247-
|> list.fold([1, n], fn(acc: List(Int), i: Int) -> List(Int) {
247+
|> list.fold([1, n], fn(acc, i) {
248248
case n % i == 0 {
249249
True -> [i, n / i, ..acc]
250250
False -> acc
@@ -260,7 +260,7 @@ fn find_divisors(n: Int) -> List(Int) {
260260
/// </a>
261261
/// </div>
262262
///
263-
/// The function returns all the positive divisors of an integer, excluding the
263+
/// The function returns all the positive divisors of an integer, excluding the
264264
/// number iteself.
265265
///
266266
/// <details>
@@ -288,7 +288,7 @@ fn find_divisors(n: Int) -> List(Int) {
288288
/// </div>
289289
///
290290
pub fn proper_divisors(n: Int) -> List(Int) {
291-
let divisors: List(Int) = find_divisors(n)
291+
let divisors = find_divisors(n)
292292
divisors
293293
|> list.take(list.length(divisors) - 1)
294294
}
@@ -340,12 +340,10 @@ pub fn float_sum(arr: List(Float), weights: option.Option(List(Float))) -> Float
340340
[], _ -> 0.0
341341
_, option.None ->
342342
arr
343-
|> list.fold(0.0, fn(acc: Float, a: Float) -> Float { a +. acc })
343+
|> list.fold(0.0, fn(acc, a) { a +. acc })
344344
_, option.Some(warr) -> {
345345
list.zip(arr, warr)
346-
|> list.fold(0.0, fn(acc: Float, a: #(Float, Float)) -> Float {
347-
pair.first(a) *. pair.second(a) +. acc
348-
})
346+
|> list.fold(0.0, fn(acc, a) { pair.first(a) *. pair.second(a) +. acc })
349347
}
350348
}
351349
}
@@ -362,7 +360,7 @@ pub fn float_sum(arr: List(Float), weights: option.Option(List(Float))) -> Float
362360
/// \sum_{i=1}^n x_i
363361
/// \\]
364362
///
365-
/// In the formula, \\(n\\) is the length of the list and \\(x_i \in \mathbb{Z}\\) is
363+
/// In the formula, \\(n\\) is the length of the list and \\(x_i \in \mathbb{Z}\\) is
366364
/// the value in the input list indexed by \\(i\\).
367365
///
368366
/// <details>
@@ -395,7 +393,7 @@ pub fn int_sum(arr: List(Int)) -> Int {
395393
[] -> 0
396394
_ ->
397395
arr
398-
|> list.fold(0, fn(acc: Int, a: Int) -> Int { a + acc })
396+
|> list.fold(0, fn(acc, a) { a + acc })
399397
}
400398
}
401399

@@ -414,7 +412,7 @@ pub fn int_sum(arr: List(Int)) -> Int {
414412
/// In the formula, \\(n\\) is the length of the list and \\(x_i \in \mathbb{R}\\) is
415413
/// the value in the input list indexed by \\(i\\), while the \\(w_i \in \mathbb{R}\\)
416414
/// are corresponding weights (\\(w_i = 1.0\\;\forall i=1...n\\) by default).
417-
///
415+
///
418416
/// <details>
419417
/// <summary>Example:</summary>
420418
///
@@ -451,20 +449,20 @@ pub fn float_product(
451449
|> Ok
452450
_, option.None ->
453451
arr
454-
|> list.fold(1.0, fn(acc: Float, a: Float) -> Float { a *. acc })
452+
|> list.fold(1.0, fn(acc, a) { a *. acc })
455453
|> Ok
456454
_, option.Some(warr) -> {
457455
let results =
458456
list.zip(arr, warr)
459-
|> list.map(fn(a: #(Float, Float)) -> Result(Float, String) {
457+
|> list.map(fn(a) {
460458
pair.first(a)
461459
|> elementary.power(pair.second(a))
462460
})
463461
|> result.all
464462
case results {
465463
Ok(prods) ->
466464
prods
467-
|> list.fold(1.0, fn(acc: Float, a: Float) -> Float { a *. acc })
465+
|> list.fold(1.0, fn(acc, a) { a *. acc })
468466
|> Ok
469467
Error(msg) ->
470468
msg
@@ -486,7 +484,7 @@ pub fn float_product(
486484
/// \prod_{i=1}^n x_i
487485
/// \\]
488486
///
489-
/// In the formula, \\(n\\) is the length of the list and \\(x_i \in \mathbb{Z}\\) is
487+
/// In the formula, \\(n\\) is the length of the list and \\(x_i \in \mathbb{Z}\\) is
490488
/// the value in the input list indexed by \\(i\\).
491489
///
492490
/// <details>
@@ -519,7 +517,7 @@ pub fn int_product(arr: List(Int)) -> Int {
519517
[] -> 1
520518
_ ->
521519
arr
522-
|> list.fold(1, fn(acc: Int, a: Int) -> Int { a * acc })
520+
|> list.fold(1, fn(acc, a) { a * acc })
523521
}
524522
}
525523

@@ -536,7 +534,7 @@ pub fn int_product(arr: List(Int)) -> Int {
536534
/// \\]
537535
///
538536
/// In the formula, \\(v_j\\) is the \\(j\\)'th element in the cumulative sum of \\(n\\)
539-
/// elements. That is, \\(n\\) is the length of the list and \\(x_i \in \mathbb{R}\\)
537+
/// elements. That is, \\(n\\) is the length of the list and \\(x_i \in \mathbb{R}\\)
540538
/// is the value in the input list indexed by \\(i\\). The value \\(v_j\\) is thus the
541539
/// sum of the \\(1\\) to \\(j\\) first elements in the given list.
542540
///
@@ -569,7 +567,7 @@ pub fn float_cumulative_sum(arr: List(Float)) -> List(Float) {
569567
[] -> []
570568
_ ->
571569
arr
572-
|> list.scan(0.0, fn(acc: Float, a: Float) -> Float { a +. acc })
570+
|> list.scan(0.0, fn(acc, a) { a +. acc })
573571
}
574572
}
575573

@@ -586,7 +584,7 @@ pub fn float_cumulative_sum(arr: List(Float)) -> List(Float) {
586584
/// \\]
587585
///
588586
/// In the formula, \\(v_j\\) is the \\(j\\)'th element in the cumulative sum of \\(n\\)
589-
/// elements. That is, \\(n\\) is the length of the list and \\(x_i \in \mathbb{Z}\\)
587+
/// elements. That is, \\(n\\) is the length of the list and \\(x_i \in \mathbb{Z}\\)
590588
/// is the value in the input list indexed by \\(i\\). The value \\(v_j\\) is thus the
591589
/// sum of the \\(1\\) to \\(j\\) first elements in the given list.
592590
///
@@ -619,7 +617,7 @@ pub fn int_cumulative_sum(arr: List(Int)) -> List(Int) {
619617
[] -> []
620618
_ ->
621619
arr
622-
|> list.scan(0, fn(acc: Int, a: Int) -> Int { a + acc })
620+
|> list.scan(0, fn(acc, a) { a + acc })
623621
}
624622
}
625623

@@ -635,10 +633,10 @@ pub fn int_cumulative_sum(arr: List(Int)) -> List(Int) {
635633
/// v_j = \prod_{i=1}^j x_i \\;\\; \forall j = 1,\dots, n
636634
/// \\]
637635
///
638-
/// In the formula, \\(v_j\\) is the \\(j\\)'th element in the cumulative product of
639-
/// \\(n\\) elements. That is, \\(n\\) is the length of the list and
640-
/// \\(x_i \in \mathbb{R}\\) is the value in the input list indexed by \\(i\\). The
641-
/// value \\(v_j\\) is thus the sum of the \\(1\\) to \\(j\\) first elements in the
636+
/// In the formula, \\(v_j\\) is the \\(j\\)'th element in the cumulative product of
637+
/// \\(n\\) elements. That is, \\(n\\) is the length of the list and
638+
/// \\(x_i \in \mathbb{R}\\) is the value in the input list indexed by \\(i\\). The
639+
/// value \\(v_j\\) is thus the sum of the \\(1\\) to \\(j\\) first elements in the
642640
/// given list.
643641
///
644642
/// <details>
@@ -671,7 +669,7 @@ pub fn float_cumulative_product(arr: List(Float)) -> List(Float) {
671669
[] -> []
672670
_ ->
673671
arr
674-
|> list.scan(1.0, fn(acc: Float, a: Float) -> Float { a *. acc })
672+
|> list.scan(1.0, fn(acc, a) { a *. acc })
675673
}
676674
}
677675

@@ -687,9 +685,9 @@ pub fn float_cumulative_product(arr: List(Float)) -> List(Float) {
687685
/// v_j = \prod_{i=1}^j x_i \\;\\; \forall j = 1,\dots, n
688686
/// \\]
689687
///
690-
/// In the formula, \\(v_j\\) is the \\(j\\)'th element in the cumulative product of
691-
/// \\(n\\) elements. That is, \\(n\\) is the length of the list and
692-
/// \\(x_i \in \mathbb{Z}\\) is the value in the input list indexed by \\(i\\). The
688+
/// In the formula, \\(v_j\\) is the \\(j\\)'th element in the cumulative product of
689+
/// \\(n\\) elements. That is, \\(n\\) is the length of the list and
690+
/// \\(x_i \in \mathbb{Z}\\) is the value in the input list indexed by \\(i\\). The
693691
/// value \\(v_j\\) is thus the product of the \\(1\\) to \\(j\\) first elements in the
694692
/// given list.
695693
///
@@ -723,6 +721,6 @@ pub fn int_cumulative_product(arr: List(Int)) -> List(Int) {
723721
[] -> []
724722
_ ->
725723
arr
726-
|> list.scan(1, fn(acc: Int, a: Int) -> Int { a * acc })
724+
|> list.scan(1, fn(acc, a) { a * acc })
727725
}
728726
}

0 commit comments

Comments
 (0)