Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.collection/ArrayOps

ArrayOps

scala.collection.ArrayOps
See theArrayOps companion object
finalclassArrayOps[A](xs:Array[A]) extendsAnyVal

This class serves as a wrapper forArrays with many of the operations found in indexed sequences. Where needed, instances of arrays are implicitly converted into this class. There is generally no reason to create an instance explicitly or use anArrayOps type. It is better to work with plainArray types instead and rely on the implicit conversion toArrayOps when calling a method (which does not actually allocate an instance ofArrayOps because it is a value class).

NeitherArray norArrayOps are proper collection types (i.e. they do not extendIterable or evenIterableOnce).mutable.ArraySeq andimmutable.ArraySeq serve this purpose.

The difference between this class andArraySeqs is that calling transformer methods such asfilter andmap will yield an array, whereas anArraySeq will remain anArraySeq.

Type parameters

A

type of the elements contained in this array.

Attributes

Companion
object
Source
ArrayOps.scala
Graph
Supertypes
classAnyVal
traitMatchable
classAny

Members list

Value members

Concrete methods

finaldef++[B >:A :ClassTag](xs:IterableOnce[B]):Array[B]

Attributes

Source
ArrayOps.scala
finaldef++[B >:A :ClassTag](xs:Array[_ <:B]):Array[B]

Attributes

Source
ArrayOps.scala
finaldef++:[B >:A :ClassTag](prefix:IterableOnce[B]):Array[B]

Attributes

Source
ArrayOps.scala
finaldef++:[B >:A :ClassTag](prefix:Array[_ <:B]):Array[B]

Attributes

Source
ArrayOps.scala
finaldef+:[B >:A :ClassTag](x:B):Array[B]

Attributes

Source
ArrayOps.scala
finaldef:+[B >:A :ClassTag](x:B):Array[B]

Attributes

Source
ArrayOps.scala
finaldef:++[B >:A :ClassTag](suffix:IterableOnce[B]):Array[B]

Attributes

Source
ArrayOps.scala
finaldef:++[B >:A :ClassTag](suffix:Array[_ <:B]):Array[B]

Attributes

Source
ArrayOps.scala
defappended[B >:A :ClassTag](x:B):Array[B]

A copy of this array with an element appended.

A copy of this array with an element appended.

Attributes

Source
ArrayOps.scala
defappendedAll[B >:A :ClassTag](suffix:IterableOnce[B]):Array[B]

A copy of this array with all elements of a collection appended.

A copy of this array with all elements of a collection appended.

Attributes

Source
ArrayOps.scala
defappendedAll[B >:A :ClassTag](suffix:Array[_ <:B]):Array[B]

A copy of this array with all elements of an array appended.

A copy of this array with all elements of an array appended.

Attributes

Source
ArrayOps.scala

Builds a new array by applying a partial function to all elements of this array on which the function is defined.

Builds a new array by applying a partial function to all elements of this array on which the function is defined.

Type parameters

B

the element type of the returned array.

Value parameters

pf

the partial function which filters and maps the array.

Attributes

Returns

a new array resulting from applying the given partial functionpf to each element on which it is defined and collecting the results. The order of the elements is preserved.

Source
ArrayOps.scala

Finds the first element of the array for which the given partial function is defined, and applies the partial function to it.

Finds the first element of the array for which the given partial function is defined, and applies the partial function to it.

Attributes

Source
ArrayOps.scala

Iterates over combinations of elements.

Iterates over combinations of elements.

Acombination of lengthn is a sequence ofn elements selected in order of their first index in this sequence.

For example,"xyx" has two combinations of length 2. Thex is selected first:"xx","xy". The sequence"yx" is not returned as a combination because it is subsumed by"xy".

If there is more than one way to generate the same combination, only one will be returned.

For example, the result"xy" arbitrarily selected one of thex elements.

As a further illustration,"xyxx" has three different ways to generate"xy" because there are three elementsx to choose from. Moreover, there are three unordered pairs"xx" but only one is returned.

It is not specified which of these equal combinations is returned. It is an implementation detail that should not be relied on. For example, the combination"xx" does not necessarily contain the firstx in this sequence. This behavior is observable if the elements compare equal but are not identical.

As a consequence,"xyx".combinations(3).next() is"xxy": the combination does not reflect the order of the original sequence, but the order in which elements were selected, by "first index"; the order of eachx element is also arbitrary.

Attributes

Returns

An Iterator which traverses the n-element combinations of this array

Example

Array('a', 'b', 'b', 'b', 'c').combinations(2).map(runtime.ScalaRunTime.stringOf).foreach(println)// Array(a, b)// Array(a, c)// Array(b, b)// Array(b, c)Array('b', 'a', 'b').combinations(2).map(runtime.ScalaRunTime.stringOf).foreach(println)// Array(b, b)// Array(b, a)
Source
ArrayOps.scala
finaldefconcat[B >:A :ClassTag](suffix:IterableOnce[B]):Array[B]

Attributes

Source
ArrayOps.scala
finaldefconcat[B >:A :ClassTag](suffix:Array[_ <:B]):Array[B]

Attributes

Source
ArrayOps.scala
defcontains(elem:A):Boolean

Tests whether this array contains a given value as an element.

Tests whether this array contains a given value as an element.

Value parameters

elem

the element to test.

Attributes

Returns

true if this array has an element that is equal (as determined by==) toelem,false otherwise.

Source
ArrayOps.scala
defcopyToArray[B >:A](xs:Array[B]):Int

Copy elements of this array to another array.

Copy elements of this array to another array. Fills the given arrayxs starting at index 0. Copying will stop once either all the elements of this array have been copied, or the end of the array is reached.

Type parameters

B

the type of the elements of the array.

Value parameters

xs

the array to fill.

Attributes

Source
ArrayOps.scala
defcopyToArray[B >:A](xs:Array[B],start:Int):Int

Copy elements of this array to another array.

Copy elements of this array to another array. Fills the given arrayxs starting at indexstart. Copying will stop once either all the elements of this array have been copied, or the end of the array is reached.

Type parameters

B

the type of the elements of the array.

Value parameters

start

the starting index within the destination array.

xs

the array to fill.

Attributes

Source
ArrayOps.scala
defcopyToArray[B >:A](xs:Array[B],start:Int,len:Int):Int

Copy elements of this array to another array.

Copy elements of this array to another array. Fills the given arrayxs starting at indexstart with at mostlen values. Copying will stop once either all the elements of this array have been copied, or the end of the array is reached, orlen elements have been copied.

Type parameters

B

the type of the elements of the array.

Value parameters

len

the maximal number of elements to copy.

start

the starting index within the destination array.

xs

the array to fill.

Attributes

Source
ArrayOps.scala
defcount(p:A=>Boolean):Int

Counts the number of elements in this array which satisfy a predicate

Counts the number of elements in this array which satisfy a predicate

Attributes

Source
ArrayOps.scala
defdiff[B >:A](that:Seq[B]):Array[A]

Computes the multiset difference between this array and another sequence.

Computes the multiset difference between this array and another sequence.

Value parameters

that

the sequence of elements to remove

Attributes

Returns

a new array which contains all elements of this array except some of occurrences of elements that also appear inthat. If an element valuex appearsn times inthat, then the firstn occurrences ofx will not form part of the result, but any following occurrences will.

Source
ArrayOps.scala

Selects all the elements of this array ignoring the duplicates.

Selects all the elements of this array ignoring the duplicates.

Attributes

Returns

a new array consisting of all the elements of this array without duplicates.

Source
ArrayOps.scala
defdistinctBy[B](f:A=>B):Array[A]

Selects all the elements of this array ignoring the duplicates as determined by== after applying the transforming functionf.

Selects all the elements of this array ignoring the duplicates as determined by== after applying the transforming functionf.

Type parameters

B

the type of the elements after being transformed byf

Value parameters

f

The transforming function whose result is used to determine the uniqueness of each element

Attributes

Returns

a new array consisting of all the elements of this array without duplicates.

Source
ArrayOps.scala
defdrop(n:Int):Array[A]

The rest of the array without itsn first elements.

The rest of the array without itsn first elements.

Attributes

Source
ArrayOps.scala

The rest of the array without itsn last elements.

The rest of the array without itsn last elements.

Attributes

Source
ArrayOps.scala
defdropWhile(p:A=>Boolean):Array[A]

Drops longest prefix of elements that satisfy a predicate.

Drops longest prefix of elements that satisfy a predicate.

Value parameters

p

The predicate used to test elements.

Attributes

Returns

the longest suffix of this array whose first element does not satisfy the predicatep.

Source
ArrayOps.scala
defendsWith[B >:A](that:Array[B]):Boolean

Tests whether this array ends with the given array.

Tests whether this array ends with the given array.

Value parameters

that

the array to test

Attributes

Returns

true if this array hasthat as a suffix,false otherwise.

Source
ArrayOps.scala
defendsWith[B >:A](that:Iterable[B]):Boolean

Tests whether this array ends with the given sequence.

Tests whether this array ends with the given sequence.

Value parameters

that

the sequence to test

Attributes

Returns

true if this array hasthat as a suffix,false otherwise.

Source
ArrayOps.scala

Tests whether a predicate holds for at least one element of this array.

Tests whether a predicate holds for at least one element of this array.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

true if the given predicatep is satisfied by at least one element of this array, otherwisefalse

Source
ArrayOps.scala
deffilter(p:A=>Boolean):Array[A]

Selects all elements of this array which satisfy a predicate.

Selects all elements of this array which satisfy a predicate.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

a new array consisting of all elements of this array that satisfy the given predicatep.

Source
ArrayOps.scala
deffilterNot(p:A=>Boolean):Array[A]

Selects all elements of this array which do not satisfy a predicate.

Selects all elements of this array which do not satisfy a predicate.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

a new array consisting of all elements of this array that do not satisfy the given predicatep.

Source
ArrayOps.scala
deffind(p:A=>Boolean):Option[A]

Finds the first element of the array satisfying a predicate, if any.

Finds the first element of the array satisfying a predicate, if any.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

an option value containing the first element in the array that satisfiesp, orNone if none exists.

Source
ArrayOps.scala
defflatMap[B :ClassTag](f:A=>IterableOnce[B]):Array[B]

Builds a new array by applying a function to all elements of this array and using the elements of the resulting collections.

Builds a new array by applying a function to all elements of this array and using the elements of the resulting collections.

Type parameters

B

the element type of the returned array.

Value parameters

f

the function to apply to each element.

Attributes

Returns

a new array resulting from applying the given collection-valued functionf to each element of this array and concatenating the results.

Source
ArrayOps.scala
defflatMap[BS,B](f:A=>BS)(implicitasIterable:BS=>Iterable[B],m:ClassTag[B]):Array[B]

Attributes

Source
ArrayOps.scala
defflatten[B](implicitasIterable:A=>IterableOnce[B],m:ClassTag[B]):Array[B]

Flattens a two-dimensional array by concatenating all its rows into a single array.

Flattens a two-dimensional array by concatenating all its rows into a single array.

Type parameters

B

Type of row elements.

Value parameters

asIterable

A function that converts elements of this array to rows - Iterables of typeB.

Attributes

Returns

An array obtained by concatenating rows of this array.

Source
ArrayOps.scala
deffold[A1 >:A](z:A1)(op: (A1,A1)=>A1):A1

Folds the elements of this array using the specified associative binary operator.

Folds the elements of this array using the specified associative binary operator.

Type parameters

A1

a type parameter for the binary operator, a supertype ofA.

Value parameters

op

a binary operator that must be associative.

z

a neutral element for the fold operation; may be added to the result an arbitrary number of times, and must not change the result (e.g.,Nil for list concatenation, 0 for addition, or 1 for multiplication).

Attributes

Returns

the result of applying the fold operatorop between all the elements, orz if this array is empty.

Source
ArrayOps.scala
deffoldLeft[B](z:B)(op: (B,A)=>B):B

Applies a binary operator to a start value and all elements of this array, going left to right.

Applies a binary operator to a start value and all elements of this array, going left to right.

Type parameters

B

the result type of the binary operator.

Value parameters

op

the binary operator.

z

the start value.

Attributes

Returns

the result of insertingop between consecutive elements of this array, going left to right with the start valuez on the left:

op(...op(z, x_1), x_2, ..., x_n)

wherex1, ..., xn are the elements of this array. Returnsz if this array is empty.

Source
ArrayOps.scala
deffoldRight[B](z:B)(op: (A,B)=>B):B

Applies a binary operator to all elements of this array and a start value, going right to left.

Applies a binary operator to all elements of this array and a start value, going right to left.

Type parameters

B

the result type of the binary operator.

Value parameters

op

the binary operator.

z

the start value.

Attributes

Returns

the result of insertingop between consecutive elements of this array, going right to left with the start valuez on the right:

op(x_1, op(x_2, ... op(x_n, z)...))

wherex1, ..., xn are the elements of this array. Returnsz if this array is empty.

Source
ArrayOps.scala

Tests whether a predicate holds for all elements of this array.

Tests whether a predicate holds for all elements of this array.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

true if this array is empty or the given predicatep holds for all elements of this array, otherwisefalse.

Source
ArrayOps.scala
defforeach[U](f:A=>U):Unit

Applyf to each element for its side effects.

Applyf to each element for its side effects. Note: [U] parameter needed to help scalac's type inference.

Attributes

Source
ArrayOps.scala
defgroupBy[K](f:A=>K):Map[K,Array[A]]

Partitions this array into a map of arrays according to some discriminator function.

Partitions this array into a map of arrays according to some discriminator function.

Type parameters

K

the type of keys returned by the discriminator function.

Value parameters

f

the discriminator function.

Attributes

Returns

A map from keys to arrays such that the following invariant holds:

(xs groupBy f)(k) = xs filter (x => f(x) == k)

That is, every keyk is bound to an array of those elementsx for whichf(x) equalsk.

Source
ArrayOps.scala
defgroupMap[K,B :ClassTag](key:A=>K)(f:A=>B):Map[K,Array[B]]

Partitions this array into a map of arrays according to a discriminator functionkey.

Partitions this array into a map of arrays according to a discriminator functionkey. Each element in a group is transformed into a value of typeB using thevalue function.

It is equivalent togroupBy(key).mapValues(_.map(f)), but more efficient.

case class User(name: String, age: Int)def namesByAge(users: Array[User]): Map[Int, Array[String]] =  users.groupMap(_.age)(_.name)

Type parameters

B

the type of values returned by the transformation function

K

the type of keys returned by the discriminator function

Value parameters

f

the element transformation function

key

the discriminator function

Attributes

Source
ArrayOps.scala
defgrouped(size:Int):Iterator[Array[A]]

Partitions elements in fixed size arrays.

Partitions elements in fixed size arrays.

Value parameters

size

the number of elements per group

Attributes

Returns

An iterator producing arrays of sizesize, except the last will be less than sizesize if the elements don't divide evenly.

See also
Source
ArrayOps.scala
defhead:A

Selects the first element of this array.

Selects the first element of this array.

Attributes

Returns

the first element of this array.

Throws

NoSuchElementExceptionif the array is empty.

Source
ArrayOps.scala

Optionally selects the first element.

Optionally selects the first element.

Attributes

Returns

the first element of this array if it is nonempty,None if it is empty.

Source
ArrayOps.scala
defindexOf(elem:A,from:Int = ...):Int

Finds index of first occurrence of some value in this array after or at some start index.

Finds index of first occurrence of some value in this array after or at some start index.

Value parameters

elem

the element value to search for.

from

the start index

Attributes

Returns

the index>= from of the first element of this array that is equal (as determined by==) toelem, or-1, if none exists.

Source
ArrayOps.scala
defindexWhere(p:A=>Boolean,from:Int = ...):Int

Finds index of the first element satisfying some predicate after or at some start index.

Finds index of the first element satisfying some predicate after or at some start index.

Value parameters

from

the start index

p

the predicate used to test elements.

Attributes

Returns

the index>= from of the first element of this array that satisfies the predicatep, or-1, if none exists.

Source
ArrayOps.scala

Produces the range of all indices of this sequence.

Produces the range of all indices of this sequence.

Attributes

Returns

aRange value from0 to one less than the length of this array.

Source
ArrayOps.scala
definit:Array[A]

The initial part of the array without its last element.

The initial part of the array without its last element.

Attributes

Source
ArrayOps.scala

Iterates over the inits of this array.

Iterates over the inits of this array. The first value will be this array and the final one will be an empty array, with the intervening values the results of successive applications ofinit.

Attributes

Returns

an iterator over all the inits of this array

Source
ArrayOps.scala
defintersect[B >:A](that:Seq[B]):Array[A]

Computes the multiset intersection between this array and another sequence.

Computes the multiset intersection between this array and another sequence.

Value parameters

that

the sequence of elements to intersect with.

Attributes

Returns

a new array which contains all elements of this array which also appear inthat. If an element valuex appearsn times inthat, then the firstn occurrences ofx will be retained in the result, but any following occurrences will be omitted.

Source
ArrayOps.scala

Tests whether the array is empty.

Tests whether the array is empty.

Attributes

Returns

true if the array contains no elements,false otherwise.

Source
ArrayOps.scala

Attributes

Source
ArrayOps.scala

The size of this array.

The size of this array.

Attributes

Returns

the number of elements in this array.

Source
ArrayOps.scala
deflast:A

Selects the last element.

Selects the last element.

Attributes

Returns

The last element of this array.

Throws

NoSuchElementExceptionIf the array is empty.

Source
ArrayOps.scala
deflastIndexOf(elem:A,end:Int = ...):Int

Finds index of last occurrence of some value in this array before or at a given end index.

Finds index of last occurrence of some value in this array before or at a given end index.

Value parameters

elem

the element value to search for.

end

the end index.

Attributes

Returns

the index<= end of the last element of this array that is equal (as determined by==) toelem, or-1, if none exists.

Source
ArrayOps.scala
deflastIndexWhere(p:A=>Boolean,end:Int = ...):Int

Finds index of last element satisfying some predicate before or at given end index.

Finds index of last element satisfying some predicate before or at given end index.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

the index<= end of the last element of this array that satisfies the predicatep, or-1, if none exists.

Source
ArrayOps.scala

Optionally selects the last element.

Optionally selects the last element.

Attributes

Returns

the last element of this array$ if it is nonempty,None if it is empty.

Source
ArrayOps.scala
deflazyZip[B](that:Iterable[B]):LazyZip2[A,B,Array[A]]

Analogous tozip except that the elements in each collection are not consumed until a strict operation is invoked on the returnedLazyZip2 decorator.

Analogous tozip except that the elements in each collection are not consumed until a strict operation is invoked on the returnedLazyZip2 decorator.

Calls tolazyZip can be chained to support higher arities (up to 4) without incurring the expense of constructing and deconstructing intermediary tuples.

val xs = List(1, 2, 3)val res = (xs lazyZip xs lazyZip xs lazyZip xs).map((a, b, c, d) => a + b + c + d)// res == List(4, 8, 12)

Type parameters

B

the type of the second element in each eventual pair

Value parameters

that

the iterable providing the second element of each eventual pair

Attributes

Returns

a decoratorLazyZip2 that allows strict operations to be performed on the lazily evaluated pairs or chained calls tolazyZip. Implicit conversion toIterable[(A, B)] is also supported.

Source
ArrayOps.scala

Compares the length of this array to a test value.

Compares the length of this array to a test value.

Value parameters

len

the test value that gets compared with the length.

Attributes

Returns

A valuex where

x <  0       if this.length <  lenx == 0       if this.length == lenx >  0       if this.length >  len
Source
ArrayOps.scala

Method mirroringSeqOps.lengthIs for consistency, except it returns anInt becauselength is known and comparison is constant-time.

Method mirroringSeqOps.lengthIs for consistency, except it returns anInt becauselength is known and comparison is constant-time.

These operations are equivalent tolengthCompare(Int), and allow the following more readable usages:

this.lengthIs < len     // this.lengthCompare(len) < 0this.lengthIs <= len    // this.lengthCompare(len) <= 0this.lengthIs == len    // this.lengthCompare(len) == 0this.lengthIs != len    // this.lengthCompare(len) != 0this.lengthIs >= len    // this.lengthCompare(len) >= 0this.lengthIs > len     // this.lengthCompare(len) > 0

Attributes

Source
ArrayOps.scala
defmap[B](f:A=>B)(implicitct:ClassTag[B]):Array[B]

Builds a new array by applying a function to all elements of this array.

Builds a new array by applying a function to all elements of this array.

Type parameters

B

the element type of the returned array.

Value parameters

f

the function to apply to each element.

Attributes

Returns

a new array resulting from applying the given functionf to each element of this array and collecting the results.

Source
ArrayOps.scala
defmapInPlace(f:A=>A):Array[A]

Attributes

Source
ArrayOps.scala

Tests whether the array is not empty.

Tests whether the array is not empty.

Attributes

Returns

true if the array contains at least one element,false otherwise.

Source
ArrayOps.scala
defpadTo[B >:A :ClassTag](len:Int,elem:B):Array[B]

A copy of this array with an element value appended until a given target length is reached.

A copy of this array with an element value appended until a given target length is reached.

Type parameters

B

the element type of the returned array.

Value parameters

elem

the padding value

len

the target length

Attributes

Returns

a new array consisting of all elements of this array followed by the minimal number of occurrences ofelem so that the resulting collection has a length of at leastlen.

Source
ArrayOps.scala
defpartition(p:A=>Boolean): (Array[A],Array[A])

A pair of, first, all elements that satisfy predicatep and, second, all elements that do not.

A pair of, first, all elements that satisfy predicatep and, second, all elements that do not.

Attributes

Source
ArrayOps.scala
defpartitionMap[A1 :ClassTag,A2 :ClassTag](f:A=>Either[A1,A2]): (Array[A1],Array[A2])

Applies a functionf to each element of the array and returns a pair of arrays: the first one made of those values returned byf that were wrapped inscala.util.Left, and the second one made of those wrapped inscala.util.Right.

Applies a functionf to each element of the array and returns a pair of arrays: the first one made of those values returned byf that were wrapped inscala.util.Left, and the second one made of those wrapped inscala.util.Right.

Example:

val xs = Array(1, "one", 2, "two", 3, "three") partitionMap { case i: Int => Left(i) case s: String => Right(s)}// xs == (Array(1, 2, 3),//        Array(one, two, three))

Type parameters

A1

the element type of the first resulting collection

A2

the element type of the second resulting collection

Value parameters

f

the 'split function' mapping the elements of this array to anscala.util.Either

Attributes

Returns

a pair of arrays: the first one made of those values returned byf that were wrapped inscala.util.Left, and the second one made of those wrapped inscala.util.Right.

Source
ArrayOps.scala
defpatch[B >:A :ClassTag](from:Int,other:IterableOnce[B],replaced:Int):Array[B]

Returns a copy of this array with patched values.

Returns a copy of this array with patched values. Patching at negative indices is the same as patching starting at 0. Patching at indices at or larger than the length of the original array appends the patch to the end. If more values are replaced than actually exist, the excess is ignored.

Value parameters

from

The start index from which to patch

other

The patch values

replaced

The number of values in the original array that are replaced by the patch.

Attributes

Source
ArrayOps.scala

Iterates over distinct permutations of elements.

Iterates over distinct permutations of elements.

Attributes

Returns

An Iterator which traverses the distinct permutations of this array.

Example

Array('a', 'b', 'b').permutations.map(runtime.ScalaRunTime.stringOf).foreach(println)// Array(a, b, b)// Array(b, a, b)// Array(b, b, a)
Source
ArrayOps.scala
defprepended[B >:A :ClassTag](x:B):Array[B]

A copy of this array with an element prepended.

A copy of this array with an element prepended.

Attributes

Source
ArrayOps.scala
defprependedAll[B >:A :ClassTag](prefix:IterableOnce[B]):Array[B]

A copy of this array with all elements of a collection prepended.

A copy of this array with all elements of a collection prepended.

Attributes

Source
ArrayOps.scala
defprependedAll[B >:A :ClassTag](prefix:Array[_ <:B]):Array[B]

A copy of this array with all elements of an array prepended.

A copy of this array with all elements of an array prepended.

Attributes

Source
ArrayOps.scala

Returns a new array with the elements in reversed order.

Returns a new array with the elements in reversed order.

Attributes

Source
ArrayOps.scala

An iterator yielding elements in reversed order.

An iterator yielding elements in reversed order.

Note:xs.reverseIterator is the same asxs.reverse.iterator but implemented more efficiently.

Attributes

Returns

an iterator yielding the elements of this array in reversed order

Source
ArrayOps.scala
defscan[B >:A :ClassTag](z:B)(op: (B,B)=>B):Array[B]

Computes a prefix scan of the elements of the array.

Computes a prefix scan of the elements of the array.

Note: The neutral elementz may be applied more than once.

Type parameters

B

element type of the resulting array

Value parameters

op

the associative operator for the scan

z

neutral element for the operatorop

Attributes

Returns

a new array containing the prefix scan of the elements in this array

Source
ArrayOps.scala
defscanLeft[B :ClassTag](z:B)(op: (B,A)=>B):Array[B]

Produces an array containing cumulative results of applying the binary operator going left to right.

Produces an array containing cumulative results of applying the binary operator going left to right.

Type parameters

B

the result type of the binary operator.

Value parameters

op

the binary operator.

z

the start value.

Attributes

Returns

array with intermediate values. Example:

Array(1, 2, 3, 4).scanLeft(0)(_ + _) == Array(0, 1, 3, 6, 10)
Source
ArrayOps.scala
defscanRight[B :ClassTag](z:B)(op: (A,B)=>B):Array[B]

Produces an array containing cumulative results of applying the binary operator going right to left.

Produces an array containing cumulative results of applying the binary operator going right to left.

Type parameters

B

the result type of the binary operator.

Value parameters

op

the binary operator.

z

the start value.

Attributes

Returns

array with intermediate values. Example:

Array(4, 3, 2, 1).scanRight(0)(_ + _) == Array(10, 6, 3, 1, 0)
Source
ArrayOps.scala

The size of this array.

The size of this array.

Attributes

Returns

the number of elements in this array.

Source
ArrayOps.scala
defsizeCompare(otherSize:Int):Int

Compares the size of this array to a test value.

Compares the size of this array to a test value.

Value parameters

otherSize

the test value that gets compared with the size.

Attributes

Returns

A valuex where

x <  0       if this.size <  otherSizex == 0       if this.size == otherSizex >  0       if this.size >  otherSize
Source
ArrayOps.scala

Method mirroringSeqOps.sizeIs for consistency, except it returns anInt becausesize is known and comparison is constant-time.

Method mirroringSeqOps.sizeIs for consistency, except it returns anInt becausesize is known and comparison is constant-time.

These operations are equivalent tosizeCompare(Int), and allow the following more readable usages:

this.sizeIs < size     // this.sizeCompare(size) < 0this.sizeIs <= size    // this.sizeCompare(size) <= 0this.sizeIs == size    // this.sizeCompare(size) == 0this.sizeIs != size    // this.sizeCompare(size) != 0this.sizeIs >= size    // this.sizeCompare(size) >= 0this.sizeIs > size     // this.sizeCompare(size) > 0

Attributes

Source
ArrayOps.scala
defslice(from:Int,until:Int):Array[A]

Selects an interval of elements.

Selects an interval of elements. The returned array is made up of all elementsx which satisfy the invariant:

from <= indexOf(x) < until

Value parameters

from

the lowest index to include from this array.

until

the lowest index to EXCLUDE from this array.

Attributes

Returns

an array containing the elements greater than or equal to indexfrom extending up to (but not including) indexuntil of this array.

Source
ArrayOps.scala
defsliding(size:Int,step:Int = ...):Iterator[Array[A]]

Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)

Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)

Value parameters

size

the number of elements per group

step

the distance between the first elements of successive groups

Attributes

Returns

An iterator producing arrays of sizesize, except the last element (which may be the only element) will be truncated if there are fewer thansize elements remaining to be grouped.

See also
Source
ArrayOps.scala
defsortBy[B](f:A=>B)(implicitord:Ordering[B]):Array[A]

Sorts this array according to the Ordering which results from transforming an implicitly given Ordering with a transformation function.

Sorts this array according to the Ordering which results from transforming an implicitly given Ordering with a transformation function.

Type parameters

B

the target type of the transformationf, and the type where the orderingord is defined.

Value parameters

f

the transformation function mapping elements to some other domainB.

ord

the ordering assumed on domainB.

Attributes

Returns

an array consisting of the elements of this array sorted according to the ordering wherex < y iford.lt(f(x), f(y)).

See also
Source
ArrayOps.scala
defsortWith(lt: (A,A)=>Boolean):Array[A]

Sorts this array according to a comparison function.

Sorts this array according to a comparison function.

The sort is stable. That is, elements that are equal (as determined bylt) appear in the same order in the sorted sequence as in the original.

Value parameters

lt

the comparison function which tests whether its first argument precedes its second argument in the desired ordering.

Attributes

Returns

an array consisting of the elements of this array sorted according to the comparison functionlt.

Source
ArrayOps.scala
defsorted[B >:A](implicitord:Ordering[B]):Array[A]

Sorts this array according to an Ordering.

Sorts this array according to an Ordering.

The sort is stable. That is, elements that are equal (as determined bylt) appear in the same order in the sorted sequence as in the original.

Value parameters

ord

the ordering to be used to compare elements.

Attributes

Returns

an array consisting of the elements of this array sorted according to the orderingord.

See also
Source
ArrayOps.scala
defspan(p:A=>Boolean): (Array[A],Array[A])

Splits this array into a prefix/suffix pair according to a predicate.

Splits this array into a prefix/suffix pair according to a predicate.

Note:c span p is equivalent to (but more efficient than)(c takeWhile p, c dropWhile p), provided the evaluation of the predicatep does not cause any side-effects.

Value parameters

p

the test predicate

Attributes

Returns

a pair consisting of the longest prefix of this array whose elements all satisfyp, and the rest of this array.

Source
ArrayOps.scala
defsplitAt(n:Int): (Array[A],Array[A])

Splits this array into two at a given position.

Splits this array into two at a given position. Note:c splitAt n is equivalent to(c take n, c drop n).

Value parameters

n

the position at which to split.

Attributes

Returns

a pair of arrays consisting of the firstn elements of this array, and the other elements.

Source
ArrayOps.scala
defstartsWith[B >:A](that:Array[B]):Boolean

Tests whether this array starts with the given array.

Tests whether this array starts with the given array.

Attributes

Source
ArrayOps.scala
defstartsWith[B >:A](that:Array[B],offset:Int):Boolean

Tests whether this array contains the given array at a given index.

Tests whether this array contains the given array at a given index.

Value parameters

offset

the index where the array is searched.

that

the array to test

Attributes

Returns

true if the arraythat is contained in this array at indexoffset, otherwisefalse.

Source
ArrayOps.scala
defstartsWith[B >:A](that:IterableOnce[B],offset:Int = ...):Boolean

Tests whether this array contains the given sequence at a given index.

Tests whether this array contains the given sequence at a given index.

Value parameters

offset

the index where the sequence is searched.

that

the sequence to test

Attributes

Returns

true if the sequencethat is contained in this array at indexoffset, otherwisefalse.

Source
ArrayOps.scala
defstepper[S <:Stepper[_]](implicitshape:StepperShape[A,S]):S &EfficientSplit

Attributes

Source
ArrayOps.scala
deftail:Array[A]

The rest of the array without its first element.

The rest of the array without its first element.

Attributes

Source
ArrayOps.scala

Iterates over the tails of this array.

Iterates over the tails of this array. The first value will be this array and the final one will be an empty array, with the intervening values the results of successive applications oftail.

Attributes

Returns

an iterator over all the tails of this array

Source
ArrayOps.scala
deftake(n:Int):Array[A]

An array containing the firstn elements of this array.

An array containing the firstn elements of this array.

Attributes

Source
ArrayOps.scala

An array containing the lastn elements of this array.

An array containing the lastn elements of this array.

Attributes

Source
ArrayOps.scala
deftakeWhile(p:A=>Boolean):Array[A]

Takes longest prefix of elements that satisfy a predicate.

Takes longest prefix of elements that satisfy a predicate.

Value parameters

p

The predicate used to test elements.

Attributes

Returns

the longest prefix of this array whose elements all satisfy the predicatep.

Source
ArrayOps.scala
deftoArray[B >:A :ClassTag]:Array[B]

Create a copy of this array with the specified element type.

Create a copy of this array with the specified element type.

Attributes

Source
ArrayOps.scala

Attributes

Source
ArrayOps.scala
finaldeftoSeq:Seq[A]

Attributes

Source
ArrayOps.scala
deftranspose[B](implicitasArray:A=>Array[B]):Array[Array[B]]

Transposes a two dimensional array.

Transposes a two dimensional array.

Type parameters

B

Type of row elements.

Value parameters

asArray

A function that converts elements of this array to rows - arrays of typeB.

Attributes

Returns

An array obtained by replacing elements of this arrays with rows the represent.

Source
ArrayOps.scala
defunzip[A1,A2](implicitasPair:A=> (A1,A2),ct1:ClassTag[A1],ct2:ClassTag[A2]): (Array[A1],Array[A2])

Converts an array of pairs into an array of first elements and an array of second elements.

Converts an array of pairs into an array of first elements and an array of second elements.

Type parameters

A1

the type of the first half of the element pairs

A2

the type of the second half of the element pairs

Value parameters

asPair

an implicit conversion which asserts that the element type of this Array is a pair.

ct1

a class tag forA1 type parameter that is required to create an instance ofArray[A1]

ct2

a class tag forA2 type parameter that is required to create an instance ofArray[A2]

Attributes

Returns

a pair of Arrays, containing, respectively, the first and second half of each element pair of this Array.

Source
ArrayOps.scala
defunzip3[A1,A2,A3](implicitasTriple:A=> (A1,A2,A3),ct1:ClassTag[A1],ct2:ClassTag[A2],ct3:ClassTag[A3]): (Array[A1],Array[A2],Array[A3])

Converts an array of triples into three arrays, one containing the elements from each position of the triple.

Converts an array of triples into three arrays, one containing the elements from each position of the triple.

Type parameters

A1

the type of the first of three elements in the triple

A2

the type of the second of three elements in the triple

A3

the type of the third of three elements in the triple

Value parameters

asTriple

an implicit conversion which asserts that the element type of this Array is a triple.

ct1

a class tag for T1 type parameter that is required to create an instance of Array[T1]

ct2

a class tag for T2 type parameter that is required to create an instance of Array[T2]

ct3

a class tag for T3 type parameter that is required to create an instance of Array[T3]

Attributes

Returns

a triple of Arrays, containing, respectively, the first, second, and third elements from each element triple of this Array.

Source
ArrayOps.scala
defupdated[B >:A :ClassTag](index:Int,elem:B):Array[B]

A copy of this array with one single replaced element.

A copy of this array with one single replaced element.

Value parameters

elem

the replacing element

index

the position of the replacement

Attributes

Returns

a new array which is a copy of this array with the element at positionindex replaced byelem.

Throws

IndexOutOfBoundsExceptionifindex does not satisfy0 <= index < length.

Source
ArrayOps.scala

Attributes

Source
ArrayOps.scala

Creates a non-strict filter of this array.

Creates a non-strict filter of this array.

Note: the difference betweenc filter p andc withFilter p is that the former creates a new array, whereas the latter only restricts the domain of subsequentmap,flatMap,foreach, andwithFilter operations.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

an object of classArrayOps.WithFilter, which supportsmap,flatMap,foreach, andwithFilter operations. All these operations apply to those elements of this array which satisfy the predicatep.

Source
ArrayOps.scala
defzip[B](that:IterableOnce[B]):Array[(A,B)]

Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs.

Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs. If one of the two collections is longer than the other, its remaining elements are ignored.

Type parameters

B

the type of the second half of the returned pairs

Value parameters

that

The iterable providing the second half of each result pair

Attributes

Returns

a new array containing pairs consisting of corresponding elements of this array andthat. The length of the returned array is the minimum of the lengths of this array andthat.

Source
ArrayOps.scala
defzipAll[A1 >:A,B](that:Iterable[B],thisElem:A1,thatElem:B):Array[(A1,B)]

Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs.

Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs. If one of the two collections is shorter than the other, placeholder elements are used to extend the shorter collection to the length of the longer.

Value parameters

that

the iterable providing the second half of each result pair

thatElem

the element to be used to fill up the result ifthat is shorter than this array.

thisElem

the element to be used to fill up the result if this array is shorter thanthat.

Attributes

Returns

a new array containing pairs consisting of corresponding elements of this array andthat. The length of the returned array is the maximum of the lengths of this array andthat. If this array is shorter thanthat,thisElem values are used to pad the result. Ifthat is shorter than this array,thatElem values are used to pad the result.

Source
ArrayOps.scala

Zips this array with its indices.

Zips this array with its indices.

Attributes

Returns

A new array containing pairs consisting of all elements of this array paired with their index. Indices start at0.

Source
ArrayOps.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp