Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add separate packages for builtin types #1502

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
186 changes: 186 additions & 0 deletions iter/iter.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
pub typealias T[X] = Iter[X]

///|
pub fn all[T](it : Iter[T], f : (T) -> Bool) -> Bool {
it.all(f)
}

///|
pub fn any[T](it : Iter[T], f : (T) -> Bool) -> Bool {
it.any(f)
}

///|
pub fn append[T](it : Iter[T], elt : T) -> Iter[T] {
it.append(elt)
}

///|
pub fn collect[T](it : Iter[T]) -> Array[T] {
it.collect()
}

///|
pub fn concat[T](it1 : Iter[T], it2 : Iter[T]) -> Iter[T] {
it1.concat(it2)
}

///|
pub fn contains[A : Eq](it : Iter[A], elt : A) -> Bool {
it.contains(elt)
}

///|
pub fn count[T](it : Iter[T]) -> Int {
it.count()
}

///|
pub fn drop[T](it : Iter[T], n : Int) -> Iter[T] {
it.drop(n)
}

///|
pub fn drop_while[T](it : Iter[T], f : (T) -> Bool) -> Iter[T] {
it.drop_while(f)
}

///|
pub fn each[T](it : Iter[T], f : (T) -> Unit) -> Unit {
it.each(f)
}

///|
pub fn eachi[T](it : Iter[T], f : (Int, T) -> Unit) -> Unit {
it.eachi(f)
}

///|
pub fn empty[T]() -> Iter[T] {
Iter::empty()
}

///|
pub fn filter[T](it : Iter[T], f : (T) -> Bool) -> Iter[T] {
it.filter(f)
}

///|
pub fn filter_map[A, B](it : Iter[A], f : (A) -> B?) -> Iter[B] {
it.filter_map(f)
}

///|
pub fn find_first[T](it : Iter[T], f : (T) -> Bool) -> T? {
it.find_first(f)
}

///|
pub fn flat_map[T, R](it : Iter[T], f : (T) -> Iter[R]) -> Iter[R] {
it.flat_map(f)
}

///|
pub fn fold[T, B](it : Iter[T], init~ : B, f : (B, T) -> B) -> B {
it.fold(init~, f)
}

///|
pub fn head[A](it : Iter[A]) -> A? {
it.head()
}

///|
pub fn intersperse[A](it : Iter[A], sep : A) -> Iter[A] {
it.intersperse(sep)
}

///|
pub fn iter[T](it : Iter[T]) -> Iter[T] {
it.iter()
}

///|
pub fn just_run[T](it : Iter[T], f : (T) -> IterResult) -> Unit {
it.just_run(f)
}

///|
pub fn last[A](it : Iter[A]) -> A? {
it.last()
}

///|
pub fn map[T, R](it : Iter[T], f : (T) -> R) -> Iter[R] {
it.map(f)
}

///|
pub fn map_while[A, B](it : Iter[A], f : (A) -> B?) -> Iter[B] {
it.map_while(f)
}

///|
pub fn new[T](f : ((T) -> IterResult) -> IterResult) -> Iter[T] {
Iter::new(f)
}

///|
pub fn peek[T](it : Iter[T]) -> T? {
it.peek()
}

///|
pub fn prepend[T](it : Iter[T], elt : T) -> Iter[T] {
it.prepend(elt)
}

///|
pub fn repeat[T](elt : T) -> Iter[T] {
Iter::repeat(elt)
}

///|
pub fn run[T](it : Iter[T], f : (T) -> IterResult) -> IterResult {
it.run(f)
}

///|
pub fn singleton[T](elt : T) -> Iter[T] {
Iter::singleton(elt)
}

///|
pub fn take[T](it : Iter[T], n : Int) -> Iter[T] {
it.take(n)
}

///|
pub fn take_while[T](it : Iter[T], f : (T) -> Bool) -> Iter[T] {
it.take_while(f)
}

///|
pub fn tap[T](it : Iter[T], f : (T) -> Unit) -> Iter[T] {
it.tap(f)
}

///|
pub fn to_array[T](it : Iter[T]) -> Array[T] {
it.to_array()
}
78 changes: 78 additions & 0 deletions iter/iter.mbti
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package moonbitlang/core/iter

// Values
fn all[T](Iter[T], (T) -> Bool) -> Bool

fn any[T](Iter[T], (T) -> Bool) -> Bool

fn append[T](Iter[T], T) -> Iter[T]

fn collect[T](Iter[T]) -> Array[T]

fn concat[T](Iter[T], Iter[T]) -> Iter[T]

fn contains[A : Eq](Iter[A], A) -> Bool

fn count[T](Iter[T]) -> Int

fn drop[T](Iter[T], Int) -> Iter[T]

fn drop_while[T](Iter[T], (T) -> Bool) -> Iter[T]

fn each[T](Iter[T], (T) -> Unit) -> Unit

fn eachi[T](Iter[T], (Int, T) -> Unit) -> Unit

fn empty[T]() -> Iter[T]

fn filter[T](Iter[T], (T) -> Bool) -> Iter[T]

fn filter_map[A, B](Iter[A], (A) -> B?) -> Iter[B]

fn find_first[T](Iter[T], (T) -> Bool) -> T?

fn flat_map[T, R](Iter[T], (T) -> Iter[R]) -> Iter[R]

fn fold[T, B](Iter[T], init~ : B, (B, T) -> B) -> B

fn head[A](Iter[A]) -> A?

fn intersperse[A](Iter[A], A) -> Iter[A]

fn iter[T](Iter[T]) -> Iter[T]

fn just_run[T](Iter[T], (T) -> IterResult) -> Unit

fn last[A](Iter[A]) -> A?

fn map[T, R](Iter[T], (T) -> R) -> Iter[R]

fn map_while[A, B](Iter[A], (A) -> B?) -> Iter[B]

fn new[T](((T) -> IterResult) -> IterResult) -> Iter[T]

fn peek[T](Iter[T]) -> T?

fn prepend[T](Iter[T], T) -> Iter[T]

fn repeat[T](T) -> Iter[T]

fn run[T](Iter[T], (T) -> IterResult) -> IterResult

fn singleton[T](T) -> Iter[T]

fn take[T](Iter[T], Int) -> Iter[T]

fn take_while[T](Iter[T], (T) -> Bool) -> Iter[T]

fn tap[T](Iter[T], (T) -> Unit) -> Iter[T]

fn to_array[T](Iter[T]) -> Array[T]

// Types and methods

// Type aliases
pub typealias T[X] = Iter[X]

// Traits

5 changes: 5 additions & 0 deletions iter/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"import": [
"moonbitlang/core/builtin"
]
}
46 changes: 46 additions & 0 deletions iter2/iter2.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
pub typealias T[X, Y] = Iter2[X, Y]

///|
pub fn each[A, B](it : Iter2[A, B], f : (A, B) -> Unit) -> Unit {
it.each(f)
}

///|
pub fn iter[A, B](it : Iter2[A, B]) -> Iter[(A, B)] {
it.iter()
}

///|
pub fn iter2[A, B](it : Iter2[A, B]) -> Iter2[A, B] {
it.iter2()
}

///|
pub fn new[A, B](f : ((A, B) -> IterResult) -> IterResult) -> Iter2[A, B] {
Iter2::new(f)
}

///|
pub fn run[A, B](it : Iter2[A, B], f : (A, B) -> IterResult) -> IterResult {
it.run(f)
}

///|
pub fn to_array[A, B](it : Iter2[A, B]) -> Array[(A, B)] {
it.to_array()
}
22 changes: 22 additions & 0 deletions iter2/iter2.mbti
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package moonbitlang/core/iter2

// Values
fn each[A, B](Iter2[A, B], (A, B) -> Unit) -> Unit

fn iter[A, B](Iter2[A, B]) -> Iter[(A, B)]

fn iter2[A, B](Iter2[A, B]) -> Iter2[A, B]

fn new[A, B](((A, B) -> IterResult) -> IterResult) -> Iter2[A, B]

fn run[A, B](Iter2[A, B], (A, B) -> IterResult) -> IterResult

fn to_array[A, B](Iter2[A, B]) -> Array[(A, B)]

// Types and methods

// Type aliases
pub typealias T[X, Y] = Iter2[X, Y]

// Traits

5 changes: 5 additions & 0 deletions iter2/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"import": [
"moonbitlang/core/builtin"
]
}
Loading
Loading