Skip to content

Commit e7f9455

Browse files
authored
Merge branch 'main' into fix_fmod
2 parents 69ad70e + 3914a3e commit e7f9455

38 files changed

+271
-38
lines changed

array/array.mbt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn Array::shuffle[T](arr : Array[T], rand~ : (Int) -> Int) -> Array[T] {
111111
///
112112
/// # Returns
113113
///
114-
pub fn map_option[A, B](self : Array[A], f : (A) -> B?) -> Array[B] {
114+
pub fn filter_map[A, B](self : Array[A], f : (A) -> B?) -> Array[B] {
115115
let result = []
116116
self.each(fn {
117117
x =>
@@ -123,6 +123,21 @@ pub fn map_option[A, B](self : Array[A], f : (A) -> B?) -> Array[B] {
123123
result
124124
}
125125
126+
///|
127+
/// Returns a new array containing the elements of the original array that satisfy the given predicate.
128+
///
129+
/// # Arguments
130+
///
131+
/// * `self` - The array to filter.
132+
/// * `f` - The predicate function.
133+
///
134+
/// # Returns
135+
///
136+
/// @alert deprecated "Use `Array::filter_map` instead"
137+
pub fn map_option[A, B](self : Array[A], f : (A) -> B?) -> Array[B] {
138+
self.filter_map(f)
139+
}
140+
126141
///|
127142
/// Returns the last element of the array.
128143
pub fn last[A](self : Array[A]) -> A? {

array/array.mbti

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ impl FixedArray {
4949

5050
impl Array {
5151
copy[T](Self[T]) -> Self[T]
52+
filter_map[A, B](Self[A], (A) -> B?) -> Self[B]
5253
from_iter[T](Iter[T]) -> Self[T]
5354
last[A](Self[A]) -> A?
5455
makei[T](Int, (Int) -> T) -> Self[T]
55-
map_option[A, B](Self[A], (A) -> B?) -> Self[B]
56+
map_option[A, B](Self[A], (A) -> B?) -> Self[B] //deprecated
5657
push_iter[T](Self[T], Iter[T]) -> Unit
5758
shuffle[T](Self[T], rand~ : (Int) -> Int) -> Self[T]
5859
shuffle_in_place[T](Self[T], rand~ : (Int) -> Int) -> Unit

array/array_test.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ test "Array::makei with negative length" {
513513
assert_eq!(arr, [])
514514
}
515515

516-
test "map_option" {
516+
test "filter_map" {
517517
let arr = [1, 2, 3, 4, 5]
518-
let mapped = arr.map_option(fn(x) { if x % 2 == 0 { Some(x) } else { None } })
518+
let mapped = arr.filter_map(fn(x) { if x % 2 == 0 { Some(x) } else { None } })
519519
inspect!(mapped, content="[2, 4]")
520520
}
521521

array/deprecated.mbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
///|
1616
/// Create a new array. Values are lazily built.
1717
/// @alert deprecated "Use `FixedArray::makei` instead"
18+
/// @coverage.skip
1819
pub fn FixedArray::new[T](length : Int, value : () -> T) -> FixedArray[T] {
1920
if length <= 0 {
2021
[]
@@ -30,6 +31,7 @@ pub fn FixedArray::new[T](length : Int, value : () -> T) -> FixedArray[T] {
3031
///|
3132
/// Create a new array. Values are built from indexes.
3233
/// @alert deprecated "Use `FixedArray::makei` instead"
34+
/// @coverage.skip
3335
pub fn FixedArray::new_with_index[T](
3436
length : Int,
3537
value : (Int) -> T
@@ -46,6 +48,7 @@ pub fn FixedArray::new_with_index[T](
4648
/// assert_eq!(sum, 15)
4749
/// ```
4850
/// @alert deprecated "Use `fold` instead"
51+
/// @coverage.skip
4952
pub fn fold_left[T, U](self : FixedArray[T], f : (U, T) -> U, init~ : U) -> U {
5053
self.fold(init~, f)
5154
}
@@ -59,6 +62,7 @@ pub fn fold_left[T, U](self : FixedArray[T], f : (U, T) -> U, init~ : U) -> U {
5962
/// assert_eq!(sum, 15)
6063
/// ```
6164
/// @alert deprecated "Use `rev_fold` instead"
65+
/// @coverage.skip
6266
pub fn fold_right[T, U](self : FixedArray[T], f : (U, T) -> U, init~ : U) -> U {
6367
self.rev_fold(init~, f)
6468
}
@@ -72,6 +76,7 @@ pub fn fold_right[T, U](self : FixedArray[T], f : (U, T) -> U, init~ : U) -> U {
7276
/// assert_eq!(sum, 10)
7377
/// ```
7478
/// @alert deprecated "Use `foldi` instead"
79+
/// @coverage.skip
7580
pub fn fold_lefti[T, U](
7681
self : FixedArray[T],
7782
f : (Int, U, T) -> U,
@@ -89,6 +94,7 @@ pub fn fold_lefti[T, U](
8994
/// assert_eq!(sum, 10)
9095
/// ```
9196
/// @alert deprecated "Use `rev_foldi` instead"
97+
/// @coverage.skip
9298
pub fn fold_righti[T, U](
9399
self : FixedArray[T],
94100
f : (Int, U, T) -> U,

buffer/deprecated.mbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/// Return a new string contains the data in buffer.
1717
///
1818
/// @alert deprecated "Use `Buffer::contents` to read the contents of the buffer"
19+
/// @coverage.skip
1920
pub fn to_string(self : T) -> String {
2021
self.contents().to_unchecked_string(offset=0, length=self.len)
2122
}
@@ -26,13 +27,15 @@ pub fn to_string(self : T) -> String {
2627
/// it simply copy the bytes into a new String.
2728
///
2829
/// @alert deprecated "Use `Buffer::contents` to read the contents of the buffer"
30+
/// @coverage.skip
2931
pub fn to_unchecked_string(self : T) -> String {
3032
self.contents().to_unchecked_string(offset=0, length=self.len)
3133
}
3234

3335
///|
3436
/// Write a sub-string into buffer.
3537
/// @alert deprecated "Use `Buffer::write_substring` instead"
38+
/// @coverage.skip
3639
pub fn write_sub_string(
3740
self : T,
3841
value : String,

builtin/array.mbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ pub fn search[T : Eq](self : Array[T], value : T) -> Int? {
572572
573573
///|
574574
/// @alert deprecated "Use `search_by` instead."
575+
/// @coverage.skip
575576
pub fn find_index[T](self : Array[T], f : (T) -> Bool) -> Int? {
576577
search_by(self, f)
577578
}
@@ -868,6 +869,7 @@ pub fn rev_foldi[A, B](self : Array[A], init~ : B, f : (Int, B, A) -> B) -> B {
868869
/// assert_eq!(sum, 15)
869870
/// ```
870871
/// @alert deprecated "Use `fold` instead."
872+
/// @coverage.skip
871873
pub fn fold_left[T, U](self : Array[T], f : (U, T) -> U, init~ : U) -> U {
872874
self.fold(init~, f)
873875
}
@@ -881,6 +883,7 @@ pub fn fold_left[T, U](self : Array[T], f : (U, T) -> U, init~ : U) -> U {
881883
/// assert_eq!(sum, 15)
882884
/// ```
883885
/// @alert deprecated "Use `rev_fold` instead."
886+
/// @coverage.skip
884887
pub fn fold_right[T, U](self : Array[T], f : (U, T) -> U, init~ : U) -> U {
885888
self.rev_fold(init~, f)
886889
}
@@ -894,6 +897,7 @@ pub fn fold_right[T, U](self : Array[T], f : (U, T) -> U, init~ : U) -> U {
894897
/// assert_eq!(sum, 10)
895898
/// ```
896899
/// @alert deprecated "Use `foldi` instead."
900+
/// @coverage.skip
897901
pub fn fold_lefti[T, U](self : Array[T], f : (Int, U, T) -> U, init~ : U) -> U {
898902
self.foldi(init~, f)
899903
}
@@ -907,6 +911,7 @@ pub fn fold_lefti[T, U](self : Array[T], f : (Int, U, T) -> U, init~ : U) -> U {
907911
/// assert_eq!(sum, 10)
908912
/// ```
909913
/// @alert deprecated "Use `rev_foldi` instead."
914+
/// @coverage.skip
910915
pub fn fold_righti[T, U](self : Array[T], f : (Int, U, T) -> U, init~ : U) -> U {
911916
self.rev_foldi(init~, f)
912917
}

builtin/arraycore_js.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ pub fn pop[T](self : Array[T]) -> T? {
199199
200200
///|
201201
/// @alert deprecated "Use `unsafe_pop` instead"
202+
/// @coverage.skip
202203
pub fn pop_exn[T](self : Array[T]) -> T {
203204
self.unsafe_pop()
204205
}

builtin/arraycore_nonjs.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ pub fn pop[T](self : Array[T]) -> T? {
237237
238238
///|
239239
/// @alert deprecated "Use `unsafe_pop` instead"
240+
/// @coverage.skip
240241
pub fn pop_exn[T](self : Array[T]) -> T {
241242
self.unsafe_pop()
242243
}

builtin/bigint_deprecated.mbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
///|
1616
/// @alert deprecated "Use infix bitwise operator `>>` instead"
17+
/// @coverage.skip
1718
pub fn asr(self : BigInt, n : Int) -> BigInt {
1819
self >> n
1920
}
@@ -24,6 +25,7 @@ pub fn asr(self : BigInt, n : Int) -> BigInt {
2425
/// Only the absolute value is shifted.
2526
///
2627
/// @alert deprecated "Use infix bitwise operator `<<` instead"
28+
/// @coverage.skip
2729
pub fn shl(self : BigInt, n : Int) -> BigInt {
2830
self << n
2931
}
@@ -34,6 +36,7 @@ pub fn shl(self : BigInt, n : Int) -> BigInt {
3436
/// Only the absolute value is shifted.
3537
///
3638
/// @alert deprecated "Use infix bitwise operator `<<` instead"
39+
/// @coverage.skip
3740
pub fn lsl(self : BigInt, n : Int) -> BigInt {
3841
self << n
3942
}
@@ -44,6 +47,7 @@ pub fn lsl(self : BigInt, n : Int) -> BigInt {
4447
/// Only the absolute value is shifted.
4548
///
4649
/// @alert deprecated "Use infix bitwise operator `>>` instead"
50+
/// @coverage.skip
4751
pub fn shr(self : BigInt, n : Int) -> BigInt {
4852
self >> n
4953
}

builtin/builtin.mbti

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ fn assert_not_eq[T : Eq + Show](T, T, loc~ : SourceLoc = _) -> Unit!
1111

1212
fn assert_true(Bool, loc~ : SourceLoc = _) -> Unit!
1313

14+
fn dump[T](T, name? : String, loc~ : SourceLoc = _) -> T //deprecated
15+
1416
fn fail[T](String, loc~ : SourceLoc = _) -> T!Failure
1517

1618
fn ignore[T](T) -> Unit
@@ -179,6 +181,7 @@ impl BigInt {
179181
impl Show for BigInt
180182

181183
pub(all) type! Failure String
184+
impl Show for Failure
182185

183186
type Hasher
184187
impl Hasher {
@@ -215,6 +218,7 @@ impl Iter {
215218
eachi[T](Self[T], (Int, T) -> Unit) -> Unit
216219
empty[T]() -> Self[T]
217220
filter[T](Self[T], (T) -> Bool) -> Self[T]
221+
filter_map[A, B](Self[A], (A) -> B?) -> Self[B]
218222
find_first[T](Self[T], (T) -> Bool) -> T?
219223
flat_map[T, R](Self[T], (T) -> Self[R]) -> Self[R]
220224
fold[T, B](Self[T], init~ : B, (B, T) -> B) -> B
@@ -224,7 +228,7 @@ impl Iter {
224228
just_run[T](Self[T], (T) -> IterResult) -> Unit
225229
last[A](Self[A]) -> A?
226230
map[T, R](Self[T], (T) -> R) -> Self[R]
227-
map_option[A, B](Self[A], (A) -> B?) -> Self[B]
231+
map_option[A, B](Self[A], (A) -> B?) -> Self[B] //deprecated
228232
map_while[A, B](Self[A], (A) -> B?) -> Self[B]
229233
new[T](((T) -> IterResult) -> IterResult) -> Self[T]
230234
op_add[T](Self[T], Self[T]) -> Self[T]
@@ -621,7 +625,7 @@ impl String {
621625
op_add(String, String) -> String
622626
op_equal(String, String) -> Bool
623627
op_get(String, Int) -> Char
624-
substring(String, start~ : Int = .., end~ : Int = ..) -> String
628+
substring(String, start~ : Int = .., end? : Int) -> String
625629
to_json(String) -> Json
626630
to_string(String) -> String
627631
}

builtin/byte.mbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ pub fn Byte::op_shr(self : Byte, count : Int) -> Byte {
244244
/// Returns the resulting `Byte` value after the bitwise left shift operation.
245245
///
246246
/// @alert deprecated "Use infix operator `<<` instead"
247+
/// @coverage.skip
247248
pub fn Byte::lsl(self : Byte, count : Int) -> Byte {
248249
(self.to_int() << count).to_byte()
249250
}
@@ -259,6 +260,7 @@ pub fn Byte::lsl(self : Byte, count : Int) -> Byte {
259260
/// Returns the result of the logical shift right operation as a `Byte`.
260261
///
261262
/// @alert deprecated "Use infix operator `>>` instead"
263+
/// @coverage.skip
262264
pub fn Byte::lsr(self : Byte, count : Int) -> Byte {
263265
(self.to_uint() >> count).reinterpret_as_int().to_byte()
264266
}

builtin/bytes.mbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn unsafe_sub_string(
3737
/// starts at `byte_offset` and has length `byte_length`.
3838
///
3939
/// @alert deprecated "Use `to_unchecked_string` instead"
40+
/// @coverage.skip
4041
pub fn sub_string(self : Bytes, byte_offset : Int, byte_length : Int) -> String {
4142
self.to_unchecked_string(offset=byte_offset, length=byte_length)
4243
}
@@ -45,6 +46,7 @@ pub fn sub_string(self : Bytes, byte_offset : Int, byte_length : Int) -> String
4546
/// Create a new unchecked string from byte sequence.
4647
///
4748
/// @alert deprecated "Use `to_unchecked_string` instead"
49+
/// @coverage.skip
4850
pub fn to_string(self : Bytes) -> String {
4951
self.to_unchecked_string(offset=0, length=self.length())
5052
}
@@ -70,6 +72,7 @@ pub fn to_unchecked_string(
7072
/// Copy `length` chars from string `str`, starting at `str_offset`,
7173
/// into byte sequence `self`, starting at `bytes_offset`.
7274
/// @alert deprecated "The type Bytes is about to be changed to be immutable. Use `FixedArray[Byte]` or `Buffer` instead."
75+
/// @coverage.skip
7376
pub fn blit_from_string(
7477
self : Bytes,
7578
bytes_offset : Int,
@@ -150,6 +153,7 @@ pub fn copy(self : Bytes) -> Bytes {
150153
/// Fill UTF8 encoded char `value` into byte sequence `self`, starting at `offset`.
151154
/// It return the length of bytes has been written.
152155
/// @alert deprecated "The type Bytes is about to be changed to be immutable. Use `FixedArray[Byte]` or `Buffer` instead."
156+
/// @coverage.skip
153157
pub fn set_utf8_char(self : Bytes, offset : Int, value : Char) -> Int {
154158
let code = value.to_uint()
155159
match code {
@@ -220,6 +224,7 @@ pub fn set_utf8_char(
220224
/// It return the length of bytes has been written.
221225
/// @alert unsafe "Panic if the [value] is out of range"
222226
/// @alert deprecated "The type Bytes is about to be changed to be immutable. Use `FixedArray[Byte]` or `Buffer` instead."
227+
/// @coverage.skip
223228
pub fn set_utf16_char(self : Bytes, offset : Int, value : Char) -> Int {
224229
let code = value.to_uint()
225230
if code < 0x10000 {
@@ -245,6 +250,7 @@ pub fn set_utf16_char(self : Bytes, offset : Int, value : Char) -> Int {
245250
/// It return the length of bytes has been written.
246251
/// @alert unsafe "Panic if the [value] is out of range"
247252
/// @alert deprecated "Use `set_utf16le_char` instead"
253+
/// @coverage.skip
248254
pub fn set_utf16_char(
249255
self : FixedArray[Byte],
250256
offset : Int,

builtin/console.mbt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,33 @@
1515
///|
1616
fn println_mono(s : String) -> Unit = "%println"
1717

18+
///|
19+
fn any_to_string[T](any : T) -> String = "%any.to_string"
20+
1821
///|
1922
pub fn println[T : Show](input : T) -> Unit {
2023
println_mono(input.to_string())
2124
}
2225

2326
///|
2427
/// @alert deprecated "Use `println` instead"
28+
/// @coverage.skip
2529
pub fn print[T : Show](input : T) -> Unit {
2630
println(input)
2731
}
2832

33+
///|
34+
/// Prints and returns the value of a given expression for quick and dirty debugging.
35+
/// @alert deprecated "This function is for debugging only and should not be used in production"
36+
pub fn dump[T](t : T, name? : String, loc~ : SourceLoc = _) -> T {
37+
let name = match name {
38+
Some(name) => name
39+
None => ""
40+
}
41+
println("dump(\{name}@\{loc}) = \{any_to_string(t)}")
42+
t
43+
}
44+
2945
///|
3046
pub fn to_string(self : Bool) -> String {
3147
if self {

0 commit comments

Comments
 (0)