Skip to content

Commit 7c83c10

Browse files
authored
Merge pull request #31 from NicklasXYZ/main
Refactor
2 parents 77e13b9 + 1e31a8c commit 7c83c10

29 files changed

+8504
-9534
lines changed

README.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,44 @@ The library supports both targets: Erlang and JavaScript.
1111

1212
```gleam
1313
import gleam/float
14-
import gleam/iterator
15-
import gleam/option.{Some}
16-
import gleam_community/maths/arithmetics
17-
import gleam_community/maths/combinatorics.{WithoutRepetitions}
18-
import gleam_community/maths/elementary
19-
import gleam_community/maths/piecewise
20-
import gleam_community/maths/predicates
14+
import gleam/yielder
15+
import gleam_community/maths
2116
import gleeunit/should
2217
2318
pub fn example() {
2419
// Evaluate the sine function
25-
let result = elementary.sin(elementary.pi())
20+
let result = maths.sin(maths.pi())
2621
2722
// Set the relative and absolute tolerance
28-
let assert Ok(absolute_tol) = elementary.power(10.0, -6.0)
23+
let assert Ok(absolute_tol) = float.power(10.0, -6.0)
2924
let relative_tol = 0.0
3025
3126
// Check that the value is very close to 0.0
3227
// That is, if 'result' is within +/- 10^(-6)
33-
predicates.is_close(result, 0.0, relative_tol, absolute_tol)
28+
maths.is_close(result, 0.0, relative_tol, absolute_tol)
3429
|> should.be_true()
3530
3631
// Find the greatest common divisor
37-
arithmetics.gcd(54, 24)
32+
maths.gcd(54, 24)
3833
|> should.equal(6)
3934
4035
// Find the minimum and maximum of a list
41-
piecewise.extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
36+
maths.extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
4237
|> should.equal(Ok(#(3.0, 50.0)))
4338
4439
// Determine if a number is fractional
45-
predicates.is_fractional(0.3333)
40+
maths.is_fractional(0.3333)
4641
|> should.equal(True)
4742
4843
// Generate all k = 2 combinations of [1, 2, 3]
49-
let assert Ok(combinations) =
50-
combinatorics.list_combination([1, 2, 3], 2, Some(WithoutRepetitions))
44+
let assert Ok(combinations) = maths.list_combination([1, 2, 3], 2)
5145
combinations
52-
|> iterator.to_list()
46+
|> yielder.to_list()
5347
|> should.equal([[1, 2], [1, 3], [2, 3]])
48+
49+
// Compute the Cosine Similarity between two (orthogonal) vectors
50+
maths.cosine_similarity([#(-1.0, 1.0), #(1.0, 1.0), #(0.0, -1.0)])
51+
|> should.equal(Ok(0.0))
5452
}
5553
5654
```

gleam.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ gleam = ">= 0.32.0"
88

99
[dependencies]
1010
gleam_stdlib = "~> 0.38"
11+
gleam_yielder = ">= 1.1.0 and < 2.0.0"
1112

1213
[dev-dependencies]
1314
gleeunit = "~> 1.0"

manifest.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
# You typically do not need to edit this file
33

44
packages = [
5-
{ name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" },
5+
{ name = "gleam_stdlib", version = "0.45.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "206FCE1A76974AECFC55AEBCD0217D59EDE4E408C016E2CFCCC8FF51278F186E" },
6+
{ name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" },
67
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
78
]
89

910
[requirements]
1011
gleam_stdlib = { version = "~> 0.38" }
12+
gleam_yielder = { version = ">= 1.1.0 and < 2.0.0" }
1113
gleeunit = { version = "~> 1.0" }

0 commit comments

Comments
 (0)