Skip to content

Commit 8d080e0

Browse files
Asterlesspeter-jerry-ye
authored andcommitted
Refactor: Update the functions in @Array/fixedarray to handle error polymorphism
1 parent 192711f commit 8d080e0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

array/fixedarray.mbt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
/// ```
3030
/// TODO: change the intrinsic to match the function name
3131
#intrinsic("%fixedarray.iter")
32-
pub fn[T] FixedArray::each(self : FixedArray[T], f : (T) -> Unit) -> Unit {
32+
pub fn[T] FixedArray::each(
33+
self : FixedArray[T],
34+
f : (T) -> Unit?Error
35+
) -> Unit?Error {
3336
for v in self {
3437
f(v)
3538
}
@@ -132,7 +135,10 @@ test "eachi" {
132135
/// [1, 2, 3, 4, 5].rev_each(fn(x){ arr.push(x) })
133136
/// assert_eq(arr, [5, 4, 3, 2, 1])
134137
/// ```
135-
pub fn[T] FixedArray::rev_each(self : FixedArray[T], f : (T) -> Unit) -> Unit {
138+
pub fn[T] FixedArray::rev_each(
139+
self : FixedArray[T],
140+
f : (T) -> Unit?Error
141+
) -> Unit?Error {
136142
for i = self.length() - 1; i >= 0; i = i - 1 {
137143
f(self[i])
138144
}
@@ -322,7 +328,10 @@ test "mapi" {
322328
/// inspect(arr, content="[0, 2, 4]")
323329
/// }
324330
/// ```
325-
pub fn[T] FixedArray::makei(length : Int, value : (Int) -> T) -> FixedArray[T] {
331+
pub fn[T] FixedArray::makei(
332+
length : Int,
333+
value : (Int) -> T?Error
334+
) -> FixedArray[T]?Error {
326335
if length <= 0 {
327336
[]
328337
} else {

0 commit comments

Comments
 (0)