Skip to content

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 ?


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]
}

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

3 participants