Skip to content

Commit fee014c

Browse files
authored
Merge branch 'main' into myfreess/add-array-zip
2 parents 01aafb4 + 4a6e310 commit fee014c

File tree

7 files changed

+128
-0
lines changed

7 files changed

+128
-0
lines changed

bytes/view_pattern_test.mbt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2025 International Digital Economy Academy
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
test "View::pattern" {
16+
let view = b"\x01\x02\x03"[:]
17+
match view {
18+
[0x01, 0x02, .. rest] => inspect!(rest, content="b\"\\x03\"")
19+
_ => abort("should not happen")
20+
}
21+
}

immut/list/dps_test.mbt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2025 International Digital Economy Academy
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
///|
16+
pub enum L {
17+
Nil
18+
Cons(Int, mut tail~ : L)
19+
} derive(Eq, Show)
20+
21+
///|
22+
/// tail recursive map using dps
23+
pub fn map(self : L, f : (Int) -> Int) -> L {
24+
match self {
25+
Nil => Nil
26+
Cons(head, tail~) => {
27+
let cell = Cons(f(head), tail=Nil)
28+
map_dps(f, tail, cell)
29+
cell
30+
}
31+
}
32+
}
33+
34+
///|
35+
fn map_dps(f : (Int) -> Int, lst : L, dest : L) -> Unit {
36+
loop lst, dest {
37+
Nil, Cons(_, ..) as c => c.tail = Nil
38+
// c.tail = lst
39+
// this is a common error
40+
Cons(head, tail~), Cons(_, ..) as c => {
41+
let cell = Cons(f(head), tail=Nil)
42+
c.tail = cell
43+
continue tail, cell
44+
}
45+
_, Nil => abort("map_dps: dest is Nil")
46+
}
47+
}
48+
49+
test "map" {
50+
let lstL : L = Cons(
51+
1,
52+
tail=Cons(2, tail=Cons(3, tail=Cons(4, tail=Cons(5, tail=Nil)))),
53+
)
54+
let lst : L = map(lstL, fn { x => x * 2 })
55+
inspect!(
56+
lst,
57+
content="Cons(2, tail=Cons(4, tail=Cons(6, tail=Cons(8, tail=Cons(10, tail=Nil)))))",
58+
)
59+
}

int16/int16.mbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
///|
16+
pub let max_value : Int16 = 32767
17+
18+
///|
19+
pub let min_value : Int16 = -32768
20+
1521
///|
1622
pub fn op_add(self : Int16, that : Int16) -> Int16 {
1723
(self.to_int() + that.to_int()).to_int16()

int16/int16.mbti

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package moonbitlang/core/int16
22

33
// Values
4+
let max_value : Int16
5+
6+
let min_value : Int16
47

58
// Types and methods
69
impl Int16 {

string/view_test.mbt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ test "index_at with surrogate pairs" {
3232
inspect!(offset, content="StringIndex(6)")
3333
let offset = str.index_at(4)
3434
inspect!(offset, content="None")
35+
inspect!(
36+
str[1:2],
37+
content=
38+
#|"🤣"
39+
,
40+
)
41+
inspect!(
42+
str[1:3],
43+
content=
44+
#|"🤣🤣"
45+
,
46+
)
47+
inspect!(
48+
str[1:-1],
49+
content=
50+
#|"🤣"
51+
,
52+
)
53+
inspect!(
54+
str[1:-2],
55+
content=
56+
#|""
57+
,
58+
)
59+
inspect!(
60+
str[:-1],
61+
content=
62+
#|"🤣🤣"
63+
,
64+
)
3565
}
3666

3767
test "stringview basic" {

uint16/uint16.mbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
///|
16+
pub let max_value : UInt16 = 65535
17+
18+
///|
19+
pub let min_value : UInt16 = 0
20+
1521
///|
1622
pub fn op_add(self : UInt16, that : UInt16) -> UInt16 {
1723
(self.to_int() + that.to_int()).to_uint16()

uint16/uint16.mbti

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package moonbitlang/core/uint16
22

33
// Values
4+
let max_value : UInt16
5+
6+
let min_value : UInt16
47

58
// Types and methods
69
impl UInt16 {

0 commit comments

Comments
 (0)