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

feat(corelib): Extend trait #7132

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

julio4
Copy link
Contributor

@julio4 julio4 commented Jan 21, 2025

  • Define the Extend trait: Extend a collection with the contents of an iterator.
  • Implement ArrayExtend

Examples

let mut arr = array![1, 2, 3];
arr.extend((4..6_u32).into_iter());
assert_eq!(arr, array![1, 2, 3, 4, 5]);

Current Issue

Doing the trait bound on +IntoIterator<I> has the benefit of being able to pass any values that can be transformed in an Iterator, including Iterator themselves.
However it seems there's some inference issues:

let mut arr = array![1, 2];
arr.extend(array![3, 4, 5].into_iter());

Cause panic:

thread '<unnamed>' panicked at crates/cairo-lang-semantic/src/expr/inference.rs:1239:25:
assertion failed: impl_impl.impl_id().is_var_free(self.db)

Using +Iterator<I> works fine, but it's better to use IntoIterator here

@reviewable-StarkWare
Copy link

This change is Reviewable

@julio4 julio4 force-pushed the feat/extend_trait branch from 4c56ebb to 0ee7864 Compare January 23, 2025 22:23
@julio4 julio4 changed the title feat(corelib): Extend trait (wip) feat(corelib): Extend trait Jan 23, 2025
@julio4 julio4 marked this pull request as ready for review January 23, 2025 22:23
@julio4 julio4 force-pushed the feat/extend_trait branch from 0ee7864 to ac16d9b Compare January 27, 2025 20:44
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

Successfully merging this pull request may close these issues.

2 participants