Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion array/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ pub fn[T] push_iter(self : Array[T], iter : Iter[T]) -> Unit {
/// inspect(arr, content="[0, 2, 4]")
/// }
/// ```
pub fn[T] Array::makei(length : Int, value : (Int) -> T) -> Array[T] {
pub fn[T] Array::makei(
length : Int,
value : (Int) -> T?Error
) -> Array[T]?Error {
if length <= 0 {
[]
} else {
Expand Down
12 changes: 6 additions & 6 deletions array/array.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn[T] FixedArray::any(Self[T], (T) -> Bool?Error) -> Bool?Error
fn FixedArray::blit_from_bytesview(Self[Byte], Int, @bytes.View) -> Unit
fn[T : Eq] FixedArray::contains(Self[T], T) -> Bool
fn[T] FixedArray::copy(Self[T]) -> Self[T]
fn[T] FixedArray::each(Self[T], (T) -> Unit) -> Unit
fn[T] FixedArray::each(Self[T], (T) -> Unit?Error) -> Unit?Error
fn[T] FixedArray::eachi(Self[T], (Int, T) -> Unit?Error) -> Unit?Error
fn[T : Eq] FixedArray::ends_with(Self[T], Self[T]) -> Bool
fn[A, B] FixedArray::fold(Self[A], init~ : B, (B, A) -> B?Error) -> B?Error
Expand All @@ -51,11 +51,11 @@ fn[T] FixedArray::from_iter(Iter[T]) -> Self[T]
fn[T : Compare] FixedArray::is_sorted(Self[T]) -> Bool
fn FixedArray::join(Self[String], @string.StringView) -> String
fn[A] FixedArray::last(Self[A]) -> A?
fn[T] FixedArray::makei(Int, (Int) -> T) -> Self[T]
fn[T] FixedArray::makei(Int, (Int) -> T?Error) -> Self[T]?Error
fn[T, U] FixedArray::map(Self[T], (T) -> U?Error) -> Self[U]?Error
fn[T, U] FixedArray::mapi(Self[T], (Int, T) -> U?Error) -> Self[U]?Error
fn[T] FixedArray::rev(Self[T]) -> Self[T]
fn[T] FixedArray::rev_each(Self[T], (T) -> Unit) -> Unit
fn[T] FixedArray::rev_each(Self[T], (T) -> Unit?Error) -> Unit?Error
fn[T] FixedArray::rev_eachi(Self[T], (Int, T) -> Unit?Error) -> Unit?Error
fn[A, B] FixedArray::rev_fold(Self[A], init~ : B, (B, A) -> B?Error) -> B?Error
fn[A, B] FixedArray::rev_foldi(Self[A], init~ : B, (Int, B, A) -> B?Error) -> B?Error
Expand All @@ -78,7 +78,7 @@ fn[A, B] Array::filter_map(Self[A], (A) -> B??Error) -> Self[B]?Error
fn[T] Array::from_iter(Iter[T]) -> Self[T]
fn Array::join(Self[String], @string.StringView) -> String
fn[A] Array::last(Self[A]) -> A?
fn[T] Array::makei(Int, (Int) -> T) -> Self[T]
fn[T] Array::makei(Int, (Int) -> T?Error) -> Self[T]?Error
fn[T] Array::push_iter(Self[T], Iter[T]) -> Unit
fn[T] Array::shuffle(Self[T], rand~ : (Int) -> Int) -> Self[T]
fn[T] Array::shuffle_in_place(Self[T], rand~ : (Int) -> Int) -> Unit
Expand All @@ -101,9 +101,9 @@ fn[A, B] ArrayView::foldi(Self[A], init~ : B, (Int, B, A) -> B?Error) -> B?Error
fn[A] ArrayView::iter(Self[A]) -> Iter[A]
fn[A] ArrayView::iter2(Self[A]) -> Iter2[Int, A]
fn ArrayView::join(Self[String], @string.StringView) -> String
fn[T, U] ArrayView::map(Self[T], (T) -> U) -> Array[U]
fn[T, U] ArrayView::map(Self[T], (T) -> U?Error) -> Array[U]?Error
fn[T] ArrayView::map_inplace(Self[T], (T) -> T?Error) -> Unit?Error
fn[T, U] ArrayView::mapi(Self[T], (Int, T) -> U) -> Array[U]
fn[T, U] ArrayView::mapi(Self[T], (Int, T) -> U?Error) -> Array[U]?Error
fn[T] ArrayView::mapi_inplace(Self[T], (Int, T) -> T?Error) -> Unit?Error
fn[A, B] ArrayView::rev_fold(Self[A], init~ : B, (B, A) -> B?Error) -> B?Error
fn[A, B] ArrayView::rev_foldi(Self[A], init~ : B, (Int, B, A) -> B?Error) -> B?Error
Expand Down
17 changes: 12 additions & 5 deletions array/fixedarray.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
/// [1, 2, 3, 4, 5].each(fn(x){ arr.push(x) })
/// assert_eq(arr, [1, 2, 3, 4, 5])
/// ```
/// TODO: change the intrinsic to match the function name
#intrinsic("%fixedarray.iter")
pub fn[T] FixedArray::each(self : FixedArray[T], f : (T) -> Unit) -> Unit {
pub fn[T] FixedArray::each(
self : FixedArray[T],
f : (T) -> Unit?Error
) -> Unit?Error {
Comment on lines +30 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one uses intrinsics, so it can't be modified like this directly. @Yu-zh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove my changes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will remove the intrinsic for now.

for v in self {
f(v)
}
Expand Down Expand Up @@ -132,7 +133,10 @@ test "eachi" {
/// [1, 2, 3, 4, 5].rev_each(fn(x){ arr.push(x) })
/// assert_eq(arr, [5, 4, 3, 2, 1])
/// ```
pub fn[T] FixedArray::rev_each(self : FixedArray[T], f : (T) -> Unit) -> Unit {
pub fn[T] FixedArray::rev_each(
self : FixedArray[T],
f : (T) -> Unit?Error
) -> Unit?Error {
for i = self.length() - 1; i >= 0; i = i - 1 {
f(self[i])
}
Expand Down Expand Up @@ -322,7 +326,10 @@ test "mapi" {
/// inspect(arr, content="[0, 2, 4]")
/// }
/// ```
pub fn[T] FixedArray::makei(length : Int, value : (Int) -> T) -> FixedArray[T] {
pub fn[T] FixedArray::makei(
length : Int,
value : (Int) -> T?Error
) -> FixedArray[T]?Error {
if length <= 0 {
[]
} else {
Expand Down
7 changes: 5 additions & 2 deletions array/view.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub fn[A, B] View::rev_foldi(
/// let v2 = v[1:].map(fn (x) {x + 1})
/// assert_eq(v2, [5, 6])
/// ```
pub fn[T, U] View::map(self : View[T], f : (T) -> U) -> Array[U] {
pub fn[T, U] View::map(self : View[T], f : (T) -> U?Error) -> Array[U]?Error {
if self.length() == 0 {
return []
}
Expand Down Expand Up @@ -342,7 +342,10 @@ pub fn[T] View::map_inplace(self : View[T], f : (T) -> T?Error) -> Unit?Error {
/// let v2 = v[1:].mapi(fn (i, x) {x + i})
/// assert_eq(v2, [4, 6])
/// ```
pub fn[T, U] View::mapi(self : View[T], f : (Int, T) -> U) -> Array[U] {
pub fn[T, U] View::mapi(
self : View[T],
f : (Int, T) -> U?Error
) -> Array[U]?Error {
if self.length() == 0 {
return []
}
Expand Down
Loading