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 Array.from extension for scala 2.11 and 2.12 #658

Merged
merged 3 commits into from
Sep 17, 2024

Conversation

RustedBones
Copy link
Contributor

Without the extension, code fails to compile for scala 2.11 and 2.12 with

 value from is not a member of object Array
     val a = Array.from(xs)

Add missing extension to the compat package

@SethTisue
Copy link
Member

review by @scala/collections ?

@@ -357,6 +360,11 @@ private[compat] trait PackageShared {
new RandomExtensions(self)
}

class ArrayExtensions(private val fact: Array.type) extends AnyVal {
def from[A: ClassTag](source: TraversableOnce[A]): Array[A] =
fact.apply(source.toSeq: _*)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source match {
case it: Iterable[A] => it.toArray[A]
case _ => it.iterator.toArray[A]
}

@@ -357,6 +360,11 @@ private[compat] trait PackageShared {
new RandomExtensions(self)
}

class ArrayExtensions(private val fact: Array.type) extends AnyVal {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final class?

@SethTisue SethTisue merged commit e566811 into scala:main Sep 17, 2024
23 checks passed
@SethTisue
Copy link
Member

Thank you!

@RustedBones RustedBones deleted the array-extensions branch September 17, 2024 14:05
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.

3 participants