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

Re: subview/sublist/substring #1244

Open
alex-s168 opened this issue Feb 13, 2025 · 0 comments
Open

Re: subview/sublist/substring #1244

alex-s168 opened this issue Feb 13, 2025 · 0 comments

Comments

@alex-s168
Copy link
Contributor

All collections (CString, SmartString, Umbra, Vector, List) should support one of these operations:

# Creates a new collection by copying all the data in the range from the old collection
let .sublist(self: t, begin: USize, len: USize): t

# dest needs to have `.push(t,x):t` (like `Vector<x>`)
let .copy-range-to(self: t, begin: USize, len: USize, dest: d): d

I see that there is a [:] operator. Maybe that could be used for this.

This should also be added to the standard library:

let .copy-range-to(self: t, begin: USize, len: USize, dest: d): d= (
   let i = 0;
   while i < len {
      let x = self[i + begin];
      dest = dest.push(x);
      i = i + 1;
   };
   dest
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant