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
3 changes: 2 additions & 1 deletion array/slice.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ fn[T] FixedArraySlice::length(self : FixedArraySlice[T]) -> Int {
}

///|
fn[T] FixedArraySlice::op_get(self : FixedArraySlice[T], index : Int) -> T {
#alias(op_get)
fn[T] FixedArraySlice::at(self : FixedArraySlice[T], index : Int) -> T {
self.array[self.start + index]
}

Expand Down
3 changes: 2 additions & 1 deletion builtin/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ pub fn[T] Array::unsafe_get(self : Array[T], idx : Int) -> T {
/// ```
///
#intrinsic("%array.get")
pub fn[T] Array::op_get(self : Array[T], index : Int) -> T {
#alias(op_get)
pub fn[T] Array::at(self : Array[T], index : Int) -> T {
let len = self.length()
guard index >= 0 && index < len
self.buffer()[index]
Expand Down
3 changes: 2 additions & 1 deletion builtin/arrayview.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ pub fn[T] ArrayView::length(self : ArrayView[T]) -> Int {
/// inspect(view[0], content="3")
/// inspect(view[1], content="4")
/// ```
pub fn[T] ArrayView::op_get(self : ArrayView[T], index : Int) -> T {
#alias(op_get)
pub fn[T] ArrayView::at(self : ArrayView[T], index : Int) -> T {
guard index >= 0 && index < self.len() else {
abort(
"index out of bounds: the len is from 0 to \{self.len()} but the index is \{index}",
Expand Down
9 changes: 6 additions & 3 deletions builtin/intrinsics.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,8 @@ pub impl Default for Char with default() = "%char_default"
/// let bytes = b"\x01\x02\x03"
/// inspect(bytes[1], content="b'\\x02'")
/// ```
pub fn Bytes::op_get(self : Bytes, idx : Int) -> Byte = "%bytes_get"
#alias(op_get)
pub fn Bytes::at(self : Bytes, idx : Int) -> Byte = "%bytes_get"

///|
/// Retrieves a byte at the specified index from a byte sequence without
Expand Down Expand Up @@ -1371,7 +1372,8 @@ pub fn UInt64::to_byte(self : UInt64) -> Byte {
/// let arr = FixedArray::make(3, 42)
/// inspect(arr[1], content="42")
/// ```
pub fn[T] FixedArray::op_get(self : FixedArray[T], idx : Int) -> T = "%fixedarray.get"
#alias(op_get)
pub fn[T] FixedArray::at(self : FixedArray[T], idx : Int) -> T = "%fixedarray.get"

///|
/// Retrieves an element from a fixed-size array at the specified index without
Expand Down Expand Up @@ -1534,7 +1536,8 @@ pub fn String::length(self : String) -> Int = "%string_length"
///
/// This method has O(1) complexity.
#alias(charcode_at, deprecated)
pub fn String::op_get(self : String, idx : Int) -> Int = "%string_get"
#alias(op_get)
pub fn String::at(self : String, idx : Int) -> Int = "%string_get"

///|
/// Returns the UTF-16 code unit at a given position in the string without
Expand Down
3 changes: 2 additions & 1 deletion builtin/linked_hash_map.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ pub fn[K : Hash + Eq, V] Map::get(self : Map[K, V], key : K) -> V? {
}

///|
pub fn[K : Hash + Eq, V] Map::op_get(self : Map[K, V], key : K) -> V {
#alias(op_get)
pub fn[K : Hash + Eq, V] Map::at(self : Map[K, V], key : K) -> V {
let hash = key.hash()
for i = 0, idx = hash & self.capacity_mask {
guard self.entries[idx] is Some(entry)
Expand Down
23 changes: 15 additions & 8 deletions builtin/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ impl Show for ArgsLoc

type Array[T]
fn[T] Array::append(Self[T], Self[T]) -> Unit
#alias(op_get)
fn[T] Array::at(Self[T], Int) -> T
fn[T : Compare] Array::binary_search(Self[T], T) -> Result[Int, Int]
fn[T] Array::binary_search_by(Self[T], (T) -> Int) -> Result[Int, Int]
fn[A] Array::blit_to(Self[A], Self[A], len~ : Int, src_offset? : Int, dst_offset? : Int) -> Unit
Expand Down Expand Up @@ -106,7 +108,6 @@ fn[T, U] Array::mapi(Self[T], (Int, T) -> U raise?) -> Self[U] raise?
fn[T] Array::mapi_inplace(Self[T], (Int, T) -> T raise?) -> Unit raise?
fn[T] Array::new(capacity? : Int) -> Self[T]
fn[T] Array::op_as_view(Self[T], start? : Int, end? : Int) -> ArrayView[T]
fn[T] Array::op_get(Self[T], Int) -> T
fn[T] Array::op_set(Self[T], Int, T) -> Unit
fn[T] Array::pop(Self[T]) -> T?
fn[T] Array::push(Self[T], T) -> Unit
Expand Down Expand Up @@ -152,11 +153,12 @@ impl[X : Show] Show for Array[X]
impl[X : ToJson] ToJson for Array[X]

type ArrayView[T]
#alias(op_get)
fn[T] ArrayView::at(Self[T], Int) -> T
#deprecated
fn[T] ArrayView::blit_to(Self[T], Self[T]) -> Unit
fn[T] ArrayView::length(Self[T]) -> Int
fn[T] ArrayView::op_as_view(Self[T], start? : Int, end? : Int) -> Self[T]
fn[T] ArrayView::op_get(Self[T], Int) -> T
#deprecated
fn[T] ArrayView::op_set(Self[T], Int, T) -> Unit
#deprecated
Expand Down Expand Up @@ -268,6 +270,8 @@ impl Default for Json
impl Eq for Json

type Map[K, V]
#alias(op_get)
fn[K : Hash + Eq, V] Map::at(Self[K, V], K) -> V
fn[K, V] Map::capacity(Self[K, V]) -> Int
fn[K, V] Map::clear(Self[K, V]) -> Unit
fn[K : Hash + Eq, V] Map::contains(Self[K, V], K) -> Bool
Expand All @@ -287,7 +291,6 @@ fn[K, V] Map::keys(Self[K, V]) -> Iter[K]
fn[K, V, V2] Map::map(Self[K, V], (K, V) -> V2) -> Self[K, V2]
fn[K, V] Map::new(capacity? : Int) -> Self[K, V]
fn[K : Hash + Eq, V] Map::of(FixedArray[(K, V)]) -> Self[K, V]
fn[K : Hash + Eq, V] Map::op_get(Self[K, V], K) -> V
fn[K : Hash + Eq, V] Map::op_set(Self[K, V], K, V) -> Unit
fn[K : Hash + Eq, V] Map::remove(Self[K, V], K) -> Unit
fn[K, V] Map::retain(Self[K, V], (K, V) -> Bool) -> Unit
Expand Down Expand Up @@ -316,10 +319,11 @@ impl Logger for StringBuilder
impl Show for StringBuilder

type UninitializedArray[T]
#alias(op_get)
fn[T] UninitializedArray::at(Self[T], Int) -> T
fn[A] UninitializedArray::length(Self[A]) -> Int
fn[T] UninitializedArray::make(Int) -> Self[T]
fn[T] UninitializedArray::op_as_view(Self[T], start? : Int, end? : Int) -> ArrayView[T]
fn[T] UninitializedArray::op_get(Self[T], Int) -> T
fn[T] UninitializedArray::op_set(Self[T], Int, T) -> Unit
fn[T] UninitializedArray::unsafe_blit(Self[T], Int, Self[T], Int, Int) -> Unit

Expand Down Expand Up @@ -514,6 +518,9 @@ fn Double::until(Double, Double, step? : Double, inclusive? : Bool) -> Iter[Doub
#deprecated
fn Double::upto(Double, Double, inclusive? : Bool) -> Iter[Double]

#alias(charcode_at, deprecated)
#alias(op_get)
fn String::at(String, Int) -> Int
#alias(codepoint_length, deprecated)
fn String::char_length(String, start_offset? : Int, end_offset? : Int) -> Int
#deprecated
Expand All @@ -522,8 +529,6 @@ fn String::escape(String) -> String
#alias(charcode_length, deprecated)
fn String::length(String) -> Int
fn String::make(Int, Char) -> String
#alias(charcode_at, deprecated)
fn String::op_get(String, Int) -> Int
#deprecated
fn String::substring(String, start? : Int, end? : Int) -> String
fn String::to_string(String) -> String
Expand All @@ -535,6 +540,8 @@ fn String::unsafe_substring(String, start~ : Int, end~ : Int) -> String
fn[X : Show] Option::to_string(X?) -> String
fn[X] Option::unwrap(X?) -> X

#alias(op_get)
fn[T] FixedArray::at(Self[T], Int) -> T
fn[T : Compare] FixedArray::binary_search(Self[T], T) -> Result[Int, Int]
fn[T] FixedArray::binary_search_by(Self[T], (T) -> Int raise?) -> Result[Int, Int] raise?
fn FixedArray::blit_from_bytes(Self[Byte], Int, Bytes, Int, Int) -> Unit
Expand All @@ -547,7 +554,6 @@ fn[T] FixedArray::iter(Self[T]) -> Iter[T]
fn[T] FixedArray::iter2(Self[T]) -> Iter2[Int, T]
fn[T] FixedArray::length(Self[T]) -> Int
fn[T] FixedArray::make(Int, T) -> Self[T]
fn[T] FixedArray::op_get(Self[T], Int) -> T
fn[T] FixedArray::op_set(Self[T], Int, T) -> Unit
fn[T] FixedArray::set(Self[T], Int, T) -> Unit
fn FixedArray::set_utf16be_char(Self[Byte], Int, Char) -> Int
Expand All @@ -558,6 +564,8 @@ fn[T] FixedArray::unsafe_get(Self[T], Int) -> T
fn FixedArray::unsafe_reinterpret_as_bytes(Self[Byte]) -> Bytes
fn[T] FixedArray::unsafe_set(Self[T], Int, T) -> Unit

#alias(op_get)
fn Bytes::at(Bytes, Int) -> Byte
#deprecated
fn Bytes::copy(Bytes) -> Bytes
fn Bytes::length(Bytes) -> Int
Expand All @@ -566,7 +574,6 @@ fn Bytes::makei(Int, (Int) -> Byte raise?) -> Bytes raise?
fn Bytes::new(Int) -> Bytes
#deprecated
fn Bytes::of_string(String) -> Bytes
fn Bytes::op_get(Bytes, Int) -> Byte
fn Bytes::to_unchecked_string(Bytes, offset? : Int, length? : Int) -> String
fn Bytes::unsafe_get(Bytes, Int) -> Byte

Expand Down
3 changes: 2 additions & 1 deletion builtin/uninitialized_array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pub fn[T] UninitializedArray::make(size : Int) -> UninitializedArray[T] = "%fixe
/// - `index` : The index of the element to retrieve.
///
/// Returns the element at the specified index.
pub fn[T] UninitializedArray::op_get(
#alias(op_get)
pub fn[T] UninitializedArray::at(
self : UninitializedArray[T],
index : Int,
) -> T = "%fixedarray.get"
Expand Down
3 changes: 2 additions & 1 deletion bytes/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ fn default() -> Bytes

// Types and methods
type View
#alias(op_get)
fn View::at(Self, Int) -> Byte
fn View::data(Self) -> Bytes
fn View::find(Self, Self) -> Int?
fn View::get(Self, Int) -> Byte?
fn View::iter(Self) -> Iter[Byte]
fn View::length(Self) -> Int
fn View::op_as_view(Self, start? : Int, end? : Int) -> Self
fn View::op_get(Self, Int) -> Byte
fn View::rev_find(Self, Self) -> Int?
fn View::start_offset(Self) -> Int
fn View::to_bytes(Self) -> Bytes
Expand Down
3 changes: 2 additions & 1 deletion bytes/view.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ fn View::len(self : View) -> Int = "%bytesview.len"
/// let view = bytes[1:4] // view contains [0x02, 0x03, 0x04]
/// inspect(view[1], content="b'\\x03'")
/// ```
pub fn View::op_get(self : View, index : Int) -> Byte {
#alias(op_get)
pub fn View::at(self : View, index : Int) -> Byte {
guard index >= 0 && index < self.length() else {
abort(
"index out of bounds: the len is from 0 to \{self.length()} but the index is \{index}",
Expand Down
3 changes: 2 additions & 1 deletion deque/deque.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ pub fn[A] pop_back(self : Deque[A]) -> A? {
/// let dv = @deque.of([1, 2, 3, 4, 5])
/// inspect(dv[2], content="3")
/// ```
pub fn[A] op_get(self : Deque[A], index : Int) -> A {
#alias(op_get)
pub fn[A] at(self : Deque[A], index : Int) -> A {
if index < 0 || index >= self.len {
let len = self.len
abort(
Expand Down
3 changes: 2 additions & 1 deletion deque/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import(
type Deque[A]
fn[A] Deque::append(Self[A], Self[A]) -> Unit
fn[A] Deque::as_views(Self[A]) -> (ArrayView[A], ArrayView[A])
#alias(op_get)
fn[A] Deque::at(Self[A], Int) -> A
fn[A] Deque::back(Self[A]) -> A?
fn[A : Compare] Deque::binary_search(Self[A], A) -> Result[Int, Int]
fn[A] Deque::binary_search_by(Self[A], (A) -> Int) -> Result[Int, Int]
Expand Down Expand Up @@ -44,7 +46,6 @@ fn[A, U] Deque::mapi(Self[A], (Int, A) -> U) -> Self[U]
fn[A] Deque::new(capacity? : Int) -> Self[A]
#as_free_fn
fn[A] Deque::of(FixedArray[A]) -> Self[A]
fn[A] Deque::op_get(Self[A], Int) -> A
fn[A] Deque::op_set(Self[A], Int, A) -> Unit
fn[A] Deque::pop_back(Self[A]) -> A?
#deprecated
Expand Down
3 changes: 2 additions & 1 deletion hashmap/hashmap.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ pub fn[K : Hash + Eq, V] get(self : HashMap[K, V], key : K) -> V? {
/// let map = @hashmap.of([("key", 42)])
/// inspect(map["key"], content="42")
/// ```
pub fn[K : Hash + Eq, V] op_get(self : HashMap[K, V], key : K) -> V {
#alias(op_get)
pub fn[K : Hash + Eq, V] at(self : HashMap[K, V], key : K) -> V {
let hash = key.hash()
for i = 0, idx = hash & self.capacity_mask {
guard self.entries[idx] is Some(entry)
Expand Down
3 changes: 2 additions & 1 deletion hashmap/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import(

// Types and methods
type HashMap[K, V]
#alias(op_get)
fn[K : Hash + Eq, V] HashMap::at(Self[K, V], K) -> V
fn[K, V] HashMap::capacity(Self[K, V]) -> Int
fn[K, V] HashMap::clear(Self[K, V]) -> Unit
fn[K : Hash + Eq, V] HashMap::contains(Self[K, V], K) -> Bool
Expand All @@ -34,7 +36,6 @@ fn[K, V, V2] HashMap::map(Self[K, V], (K, V) -> V2) -> Self[K, V2]
fn[K, V] HashMap::new(capacity? : Int) -> Self[K, V]
#as_free_fn
fn[K : Eq + Hash, V] HashMap::of(FixedArray[(K, V)]) -> Self[K, V]
fn[K : Hash + Eq, V] HashMap::op_get(Self[K, V], K) -> V
fn[K : Hash + Eq, V] HashMap::op_set(Self[K, V], K, V) -> Unit
fn[K : Hash + Eq, V] HashMap::remove(Self[K, V], K) -> Unit
fn[K, V] HashMap::retain(Self[K, V], (K, V) -> Bool) -> Unit
Expand Down
3 changes: 2 additions & 1 deletion immut/array/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ pub fn[A] length(self : T[A]) -> Int {
/// let v = @array.of([1, 2, 3, 4, 5])
/// inspect(v[0], content="1")
/// ```
pub fn[A] op_get(self : T[A], index : Int) -> A {
#alias(op_get)
pub fn[A] at(self : T[A], index : Int) -> A {
if index == 0 {
self.tree.get_first()
} else if index == self.size - 1 {
Expand Down
3 changes: 2 additions & 1 deletion immut/array/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import(

// Types and methods
type T[A]
#alias(op_get)
fn[A] T::at(Self[A], Int) -> A
fn[A] T::concat(Self[A], Self[A]) -> Self[A]
#deprecated
fn[A] T::copy(Self[A]) -> Self[A]
Expand Down Expand Up @@ -38,7 +40,6 @@ fn[A, B] T::map(Self[A], (A) -> B raise?) -> Self[B] raise?
fn[A] T::new() -> Self[A]
#as_free_fn
fn[A] T::of(FixedArray[A]) -> Self[A]
fn[A] T::op_get(Self[A], Int) -> A
fn[A] T::push(Self[A], A) -> Self[A]
fn[A, B] T::rev_fold(Self[A], init~ : B, (B, A) -> B raise?) -> B raise?
fn[A] T::set(Self[A], Int, A) -> Self[A]
Expand Down
6 changes: 3 additions & 3 deletions immut/hashmap/HAMT.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn[K : Eq, V] Node::get_with_path(
}
(Branch(children), path) => {
let idx = path.idx()
if children[idx] is Some(child) {
if children.get(idx) is Some(child) {
continue (child, path.next())
}
None
Expand Down Expand Up @@ -140,7 +140,7 @@ fn[K : Eq, V] add_with_path(
}
Branch(children) => {
let idx = path.idx()
match children[idx] {
match children.get(idx) {
Some(child) => {
let child = child.add_with_path(key, value, path.next())
Branch(children.replace(idx, child))
Expand Down Expand Up @@ -322,7 +322,7 @@ fn[K : Eq, V] remove_with_path(
}
Branch(children) => {
let idx = path.idx()
match children[idx] {
match children.get(idx) {
None => Some(self)
Some(child) => {
let new_child = child.remove_with_path(key, path.next())
Expand Down
6 changes: 3 additions & 3 deletions immut/hashset/HAMT.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn[A : Eq] Node::contains(self : Node[A], key : A, path : Path) -> Bool {
(Flat(key1, path1), path) => path == path1 && key == key1
(Branch(children), path) => {
let idx = path.idx()
if children[idx] is Some(child) {
if children.get(idx) is Some(child) {
continue (child, path.next())
}
false
Expand Down Expand Up @@ -93,7 +93,7 @@ fn[A : Eq] add_with_path(self : Node[A], key : A, path : Path) -> Node[A] {
}
Branch(children) => {
let idx = path.idx()
match children[idx] {
match children.get(idx) {
Some(child) => {
let child = child.add_with_path(key, path.next())
Branch(children.replace(idx, child))
Expand Down Expand Up @@ -147,7 +147,7 @@ fn[A : Eq] remove_with_path(self : Node[A], key : A, path : Path) -> Node[A]? {
}
Branch(children) => {
let idx = path.idx()
match children[idx] {
match children.get(idx) {
None => Some(self)
Some(child) => {
let new_child = child.remove_with_path(key, path.next())
Expand Down
Loading
Loading