Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 6 additions & 12 deletions argparse/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import {
// Types and methods
pub struct ArgGroup {
// private fields

fn new(StringView, required? : Bool, multiple? : Bool, args? : ArrayView[String], requires? : ArrayView[String], conflicts_with? : ArrayView[String]) -> ArgGroup
}
pub fn ArgGroup::ArgGroup(StringView, required? : Bool, multiple? : Bool, args? : ArrayView[String], requires? : ArrayView[String], conflicts_with? : ArrayView[String]) -> Self
pub fn ArgGroup::new(StringView, required? : Bool, multiple? : Bool, args? : ArrayView[String], requires? : ArrayView[String], conflicts_with? : ArrayView[String]) -> Self

pub struct Command {
// private fields

fn new(StringView, flags? : ArrayView[FlagArg], options? : ArrayView[OptionArg], positionals? : ArrayView[PositionArg], subcommands? : ArrayView[Command], about? : StringView, version? : StringView, disable_help_flag? : Bool, disable_version_flag? : Bool, disable_help_subcommand? : Bool, arg_required_else_help? : Bool, subcommand_required? : Bool, hidden? : Bool, groups? : ArrayView[ArgGroup]) -> Command
}
pub fn Command::Command(StringView, flags? : ArrayView[FlagArg], options? : ArrayView[OptionArg], positionals? : ArrayView[PositionArg], subcommands? : ArrayView[Self], about? : StringView, version? : StringView, disable_help_flag? : Bool, disable_version_flag? : Bool, disable_help_subcommand? : Bool, arg_required_else_help? : Bool, subcommand_required? : Bool, hidden? : Bool, groups? : ArrayView[ArgGroup]) -> Self
pub fn Command::new(StringView, flags? : ArrayView[FlagArg], options? : ArrayView[OptionArg], positionals? : ArrayView[PositionArg], subcommands? : ArrayView[Self], about? : StringView, version? : StringView, disable_help_flag? : Bool, disable_version_flag? : Bool, disable_help_subcommand? : Bool, arg_required_else_help? : Bool, subcommand_required? : Bool, hidden? : Bool, groups? : ArrayView[ArgGroup]) -> Self
#as_free_fn
pub fn Command::parse(Self, argv? : ArrayView[String], env? : Map[String, String]) -> Matches raise
Expand All @@ -37,9 +35,8 @@ pub(all) enum FlagAction {

pub struct FlagArg {
// private fields

fn new(StringView, short? : Char, long? : StringView, about? : StringView, action? : FlagAction, env? : StringView, requires? : ArrayView[String], conflicts_with? : ArrayView[String], required? : Bool, global? : Bool, negatable? : Bool, hidden? : Bool) -> FlagArg
}
pub fn FlagArg::FlagArg(StringView, short? : Char, long? : StringView, about? : StringView, action? : FlagAction, env? : StringView, requires? : ArrayView[String], conflicts_with? : ArrayView[String], required? : Bool, global? : Bool, negatable? : Bool, hidden? : Bool) -> Self
pub fn FlagArg::new(StringView, short? : Char, long? : StringView, about? : StringView, action? : FlagAction, env? : StringView, requires? : ArrayView[String], conflicts_with? : ArrayView[String], required? : Bool, global? : Bool, negatable? : Bool, hidden? : Bool) -> Self

pub struct Matches {
Expand All @@ -58,23 +55,20 @@ pub(all) enum OptionAction {

pub struct OptionArg {
// private fields

fn new(StringView, short? : Char, long? : StringView, about? : StringView, action? : OptionAction, env? : StringView, default_values? : ArrayView[String], allow_hyphen_values? : Bool, requires? : ArrayView[String], conflicts_with? : ArrayView[String], required? : Bool, global? : Bool, hidden? : Bool) -> OptionArg
}
pub fn OptionArg::OptionArg(StringView, short? : Char, long? : StringView, about? : StringView, action? : OptionAction, env? : StringView, default_values? : ArrayView[String], allow_hyphen_values? : Bool, requires? : ArrayView[String], conflicts_with? : ArrayView[String], required? : Bool, global? : Bool, hidden? : Bool) -> Self
pub fn OptionArg::new(StringView, short? : Char, long? : StringView, about? : StringView, action? : OptionAction, env? : StringView, default_values? : ArrayView[String], allow_hyphen_values? : Bool, requires? : ArrayView[String], conflicts_with? : ArrayView[String], required? : Bool, global? : Bool, hidden? : Bool) -> Self

pub struct PositionArg {
// private fields

fn new(StringView, about? : StringView, env? : StringView, default_values? : ArrayView[String], num_args? : ValueRange, allow_hyphen_values? : Bool, requires? : ArrayView[String], conflicts_with? : ArrayView[String], global? : Bool, hidden? : Bool) -> PositionArg
}
pub fn PositionArg::PositionArg(StringView, about? : StringView, env? : StringView, default_values? : ArrayView[String], num_args? : ValueRange, allow_hyphen_values? : Bool, requires? : ArrayView[String], conflicts_with? : ArrayView[String], global? : Bool, hidden? : Bool) -> Self
pub fn PositionArg::new(StringView, about? : StringView, env? : StringView, default_values? : ArrayView[String], num_args? : ValueRange, allow_hyphen_values? : Bool, requires? : ArrayView[String], conflicts_with? : ArrayView[String], global? : Bool, hidden? : Bool) -> Self

pub struct ValueRange {
// private fields

fn new(lower? : Int, upper? : Int) -> ValueRange
} derive(Eq, Show)
pub fn ValueRange::ValueRange(lower? : Int, upper? : Int) -> Self
pub fn ValueRange::new(lower? : Int, upper? : Int) -> Self
pub fn ValueRange::single() -> Self

Expand Down
61 changes: 19 additions & 42 deletions builtin/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -906,70 +906,47 @@ pub fn[T : Eq] Array::ends_with(self : Array[T], suffix : Array[T]) -> Bool {
}

///|
/// Removes a prefix from an array if it exists.
/// Strip a prefix from the array.
///
/// Parameters:
///
/// * `array` : The array to remove the prefix from.
/// * `prefix` : The array to be removed from the beginning of `array`.
///
/// Returns `Some(array)` containing the remaining elements after removing the
/// prefix if the array starts with the prefix, or `None` if the array doesn't
/// start with the prefix.
///
/// Example:
/// If the array starts with the prefix, return a view of the array after the
/// prefix, otherwise return None. The returned view shares the original
/// backing array — no allocation.
///
/// # Example
/// ```mbt check
/// test {
/// let arr = [1, 2, 3, 4, 5]
/// debug_inspect(arr.strip_prefix([1, 2]), content="Some([3, 4, 5])")
/// debug_inspect(arr.strip_prefix([2, 3]), content="None")
/// let v = [1, 2, 3, 4, 5]
/// let v2 = v.strip_prefix([1, 2][:])
/// debug_inspect(v2, content="Some(<ArrayView: [3, 4, 5]>)")
/// }
/// ```
pub fn[T : Eq] Array::strip_prefix(
self : Array[T],
prefix : Array[T],
) -> Array[T]? {
if self.starts_with(prefix) {
let v = Array::make_uninit(self.length() - prefix.length())
UninitializedArray::unsafe_blit(
v.buffer(),
0,
self.buffer(),
prefix.length(),
self.length() - prefix.length(),
)
Some(v)
} else {
None
}
prefix : ArrayView[T],
) -> ArrayView[T]? {
self[:].strip_prefix(prefix)
}

///|
/// Strip a suffix from the array.
///
/// If the array ends with the suffix, return the array before the suffix, otherwise return None.
/// If the array ends with the suffix, return a view of the array before the
/// suffix, otherwise return None. The returned view shares the original
/// backing array — no allocation.
///
/// # Example
/// ```mbt check
/// test {
/// let v = [3, 4, 5]
/// let v2 = v.strip_suffix([5])
/// assert_eq(v2, Some([3, 4]))
/// let v2 = v.strip_suffix([5][:])
/// debug_inspect(v2, content="Some(<ArrayView: [3, 4]>)")
/// }
/// ```
pub fn[T : Eq] Array::strip_suffix(
self : Array[T],
suffix : Array[T],
) -> Array[T]? {
if self.ends_with(suffix) {
let v = Array::make_uninit(self.length() - suffix.length())
let len = self.length() - suffix.length()
UninitializedArray::unsafe_blit(v.buffer(), 0, self.buffer(), 0, len)
Some(v)
} else {
None
}
suffix : ArrayView[T],
) -> ArrayView[T]? {
self[:].strip_suffix(suffix)
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
}

///|
Expand Down
12 changes: 6 additions & 6 deletions builtin/array_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,17 @@ test "lexical_compare" {
///|
test "array_strip_prefix" {
let arr = [1, 2, 3]
assert_eq(arr.strip_prefix([1, 2]), Some([3]))
assert_eq(arr.strip_prefix([1, 2, 3]), Some([]))
assert_eq(arr.strip_prefix([2, 3]), None)
debug_inspect(arr.strip_prefix([1, 2][:]), content="Some(<ArrayView: [3]>)")
debug_inspect(arr.strip_prefix([1, 2, 3][:]), content="Some(<ArrayView: []>)")
debug_inspect(arr.strip_prefix([2, 3][:]), content="None")
}

///|
test "array_strip_suffix" {
let arr = [1, 2, 3]
assert_eq(arr.strip_suffix([2, 3]), Some([1]))
assert_eq(arr.strip_suffix([1, 2, 3]), Some([]))
assert_eq(arr.strip_suffix([1, 2]), None)
debug_inspect(arr.strip_suffix([2, 3][:]), content="Some(<ArrayView: [1]>)")
debug_inspect(arr.strip_suffix([1, 2, 3][:]), content="Some(<ArrayView: []>)")
debug_inspect(arr.strip_suffix([1, 2][:]), content="None")
}

///|
Expand Down
56 changes: 56 additions & 0 deletions builtin/arrayview.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,62 @@ pub fn[T : Eq] ArrayView::ends_with(
}
}

///|
/// Returns a sub-view with `prefix` removed from the start, or `None` if the
/// view does not start with `prefix`. The returned view shares the original
/// backing array — no allocation.
///
/// Example:
///
/// ```mbt check
/// test {
/// let v = [1, 2, 3, 4, 5][:]
/// debug_inspect(
/// v.strip_prefix([1, 2][:]),
/// content="Some(<ArrayView: [3, 4, 5]>)",
/// )
/// debug_inspect(v.strip_prefix([2, 3][:]), content="None")
/// }
/// ```
pub fn[T : Eq] ArrayView::strip_prefix(
self : ArrayView[T],
prefix : ArrayView[T],
) -> ArrayView[T]? {
if self.starts_with(prefix) {
Some(self[prefix.length():])
} else {
None
}
}

///|
/// Returns a sub-view with `suffix` removed from the end, or `None` if the
/// view does not end with `suffix`. The returned view shares the original
/// backing array — no allocation.
///
/// Example:
///
/// ```mbt check
/// test {
/// let v = [1, 2, 3, 4, 5][:]
/// debug_inspect(
/// v.strip_suffix([4, 5][:]),
/// content="Some(<ArrayView: [1, 2, 3]>)",
/// )
/// debug_inspect(v.strip_suffix([3, 4][:]), content="None")
/// }
/// ```
pub fn[T : Eq] ArrayView::strip_suffix(
self : ArrayView[T],
suffix : ArrayView[T],
) -> ArrayView[T]? {
if self.ends_with(suffix) {
Some(self[:self.length() - suffix.length()])
} else {
None
}
}

///|
/// Performs a binary search on a sorted array view.
///
Expand Down
76 changes: 76 additions & 0 deletions builtin/arrayview_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -914,3 +914,79 @@ test "ArrayView::windows shares backing" {
arr[1] = 99
inspect(ws, content="[[1, 99], [99, 3], [3, 4]]")
}

///|
test "ArrayView::strip_prefix basic" {
let v = [1, 2, 3, 4, 5][:]
debug_inspect(
v.strip_prefix([1, 2][:]),
content="Some(<ArrayView: [3, 4, 5]>)",
)
debug_inspect(v.strip_prefix([2, 3][:]), content="None")
}

///|
test "ArrayView::strip_prefix empty prefix" {
let v = [1, 2, 3][:]
debug_inspect(v.strip_prefix([][:]), content="Some(<ArrayView: [1, 2, 3]>)")
}

///|
test "ArrayView::strip_prefix full match" {
let v = [1, 2, 3][:]
debug_inspect(v.strip_prefix([1, 2, 3][:]), content="Some(<ArrayView: []>)")
}

///|
test "ArrayView::strip_prefix too long" {
let v = [1, 2][:]
debug_inspect(v.strip_prefix([1, 2, 3][:]), content="None")
}

///|
test "ArrayView::strip_prefix on sliced view" {
let v = [0, 1, 2, 3, 4][1:]
debug_inspect(v.strip_prefix([1, 2][:]), content="Some(<ArrayView: [3, 4]>)")
}

///|
test "ArrayView::strip_prefix shares backing" {
let arr = [1, 2, 3, 4, 5]
guard arr[:].strip_prefix([1, 2][:]) is Some(rest)
arr[2] = 99
inspect(rest, content="[99, 4, 5]")
}

///|
test "ArrayView::strip_suffix basic" {
let v = [1, 2, 3, 4, 5][:]
debug_inspect(
v.strip_suffix([4, 5][:]),
content="Some(<ArrayView: [1, 2, 3]>)",
)
debug_inspect(v.strip_suffix([3, 4][:]), content="None")
}

///|
test "ArrayView::strip_suffix empty suffix" {
let v = [1, 2, 3][:]
debug_inspect(v.strip_suffix([][:]), content="Some(<ArrayView: [1, 2, 3]>)")
}

///|
test "ArrayView::strip_suffix full match" {
let v = [1, 2, 3][:]
debug_inspect(v.strip_suffix([1, 2, 3][:]), content="Some(<ArrayView: []>)")
}

///|
test "ArrayView::strip_suffix too long" {
let v = [1, 2][:]
debug_inspect(v.strip_suffix([0, 1, 2][:]), content="None")
}

///|
test "ArrayView::strip_suffix on sliced view" {
let v = [0, 1, 2, 3, 4][:4]
debug_inspect(v.strip_suffix([2, 3][:]), content="Some(<ArrayView: [0, 1]>)")
}
6 changes: 4 additions & 2 deletions builtin/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ pub fn[T] Array::sort_by(Self[T], (T, T) -> Int) -> Unit
pub fn[T, K : Compare] Array::sort_by_key(Self[T], (T) -> K) -> Unit
pub fn[T] Array::split(Self[T], (T) -> Bool raise?) -> Self[Self[T]] raise?
pub fn[T : Eq] Array::starts_with(Self[T], Self[T]) -> Bool
pub fn[T : Eq] Array::strip_prefix(Self[T], Self[T]) -> Self[T]?
pub fn[T : Eq] Array::strip_suffix(Self[T], Self[T]) -> Self[T]?
pub fn[T : Eq] Array::strip_prefix(Self[T], ArrayView[T]) -> ArrayView[T]?
pub fn[T : Eq] Array::strip_suffix(Self[T], ArrayView[T]) -> ArrayView[T]?
pub fn[T] Array::suffixes(Self[T], include_empty? : Bool) -> Iter[ArrayView[T]]
pub fn[T] Array::swap(Self[T], Int, Int) -> Unit
pub fn[A] Array::truncate(Self[A], Int) -> Unit
Expand Down Expand Up @@ -228,6 +228,8 @@ pub fn[T : Eq] ArrayView::search(Self[T], T) -> Int?
pub fn[T] ArrayView::search_by(Self[T], (T) -> Bool raise?) -> Int? raise?
pub fn[T] ArrayView::start_offset(Self[T]) -> Int
pub fn[T : Eq] ArrayView::starts_with(Self[T], Self[T]) -> Bool
pub fn[T : Eq] ArrayView::strip_prefix(Self[T], Self[T]) -> Self[T]?
pub fn[T : Eq] ArrayView::strip_suffix(Self[T], Self[T]) -> Self[T]?
pub fn[T] ArrayView::suffixes(Self[T], include_empty? : Bool) -> Iter[Self[T]]
#alias(to_array, deprecated)
pub fn[T] ArrayView::to_owned(Self[T]) -> Array[T]
Expand Down
3 changes: 1 addition & 2 deletions internal/regex_engine/shared_types/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ pub struct Profile {
word : @rechar_set.RecharSet
word_symbolize_splits : ReadOnlyArray[@rechar_set.RecharSet]
category : (Int) -> Category

fn new(valid~ : @rechar_set.RecharSet, word~ : @rechar_set.RecharSet, word_symbolize_splits? : ReadOnlyArray[@rechar_set.RecharSet], category~ : (Int) -> Category) -> Profile
}
pub fn Profile::Profile(valid~ : @rechar_set.RecharSet, word~ : @rechar_set.RecharSet, word_symbolize_splits? : ReadOnlyArray[@rechar_set.RecharSet], category~ : (Int) -> Category) -> Self
pub fn Profile::new(valid~ : @rechar_set.RecharSet, word~ : @rechar_set.RecharSet, word_symbolize_splits? : ReadOnlyArray[@rechar_set.RecharSet], category~ : (Int) -> Category) -> Self

pub(all) enum QuantifierMode {
Expand Down
3 changes: 1 addition & 2 deletions json/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ pub(all) struct Position {

pub struct Replacer {
// private fields

fn new((String, Json) -> Json?) -> Replacer
}
pub fn Replacer::Replacer((String, Json) -> Json?) -> Self
pub fn Replacer::exclude(ArrayView[StringView]) -> Self
pub fn Replacer::keep(ArrayView[StringView]) -> Self
pub fn Replacer::new((String, Json) -> Json?) -> Self
Expand Down
3 changes: 1 addition & 2 deletions ref/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ pub fn[T] new(T) -> Ref[T]
// Types and methods
pub(all) struct Ref[T] {
mut val : T

fn[T] new(T) -> Ref[T]
}
pub fn[T] Ref::Ref(T) -> Self[T]
pub fn[T, R] Ref::map(Self[T], (T) -> R raise?) -> Self[R] raise?
pub fn[T] Ref::new(T) -> Self[T]
pub fn[T, R] Ref::protect(Self[T], T, () -> R raise?) -> R raise?
Expand Down
3 changes: 1 addition & 2 deletions string/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ pub fn MatchResult::named_group(Self, String) -> StringView?

pub struct Regex {
// private fields

fn new(StringView) -> Regex raise
}
pub fn Regex::Regex(StringView) -> Self raise
pub fn Regex::capture(Self, String) -> Self
pub fn Regex::execute(Self, StringView, last_index? : Int) -> MatchResult?
pub fn Regex::find(Self, StringView) -> Iter[MatchResult]
Expand Down
Loading