SlicingOps

io.github.scala_tessella.ring_seq.SlicingOps
trait SlicingOps extends TransformingOps

Provides slicing operations for a Seq considered circular.

Attributes

Graph
Supertypes
trait IndexingOps
class Object
trait Matchable
class Any
Known subtypes
trait IteratingOps
trait ComparingOps
object RingSeq

Members list

Type members

Inherited types

type Index = Int

For improved readability, the index of a Seq.

For improved readability, the index of a Seq.

Attributes

Inherited from:
IndexingOps
type IndexO = Int

For improved readability, the index of a circular Seq.

For improved readability, the index of a circular Seq.

Attributes

Note

any value is a valid index, provided that Seq is not empty

Inherited from:
IndexingOps

Extensions

Extensions

extension [A, CC <: (SeqOps)](ring: CC[A])
def containsSliceO(slice: Seq[A]): Boolean

Tests whether this circular sequence contains a given sequence as a slice.

Tests whether this circular sequence contains a given sequence as a slice.

Value parameters

that

the sequence to test

Attributes

Returns

true if this circular sequence contains a slice with the same elements as ''that'', otherwise false.

Example
Seq(0, 1, 2).containsSliceO(Seq(2, 0, 1, 2, 0)) // true
def indexOfSliceO(that: Seq[A], from: IndexO): Index

Finds first index after or at a start index where this circular sequence contains a given sequence as a slice.

Finds first index after or at a start index where this circular sequence contains a given sequence as a slice.

Value parameters

from

IndexO

that

the sequence to test

Attributes

Returns

the first index >= ''from'' such that the elements of this circular sequence starting at this index match the elements of sequence ''that'', or -1 if no such subsequence exists.

Example
Seq(0, 1, 2).indexOfSliceO(Seq(2, 0, 1, 2, 0)) // 2
def lastIndexOfSliceO(that: Seq[A], end: IndexO): Index

Finds last index before or at a given end index where this circular sequence contains a given sequence as a slice.

Finds last index before or at a given end index where this circular sequence contains a given sequence as a slice.

Value parameters

end

IndexO

that

the sequence to test

Attributes

Returns

the last index <= ''end'' such that the elements of this circular sequence starting at this index match the elements of sequence ''that'', or -1 if no such subsequence exists.

Example
Seq(0, 1, 2, 0, 1, 2).lastIndexOfSliceO(Seq(2, 0)) // 5
def segmentLengthO(p: A => Boolean, from: IndexO): Int

Computes the length of the longest segment that starts from some circular index and whose elements all satisfy some predicate.

Computes the length of the longest segment that starts from some circular index and whose elements all satisfy some predicate.

Value parameters

from

IndexO

p

the predicate used to test elements

Attributes

Returns

the length of the longest segment of this sequence starting from circular index ''from'' such that every element of the segment satisfies the predicate ''p''

Example
Seq(0, 1, 2).segmentLengthO(_ % 2 == 0, 2) // 2
def sliceO(from: IndexO, to: IndexO): CC[A]

Selects an interval of elements.

Selects an interval of elements.

Value parameters

from

IndexO

until

IndexO

Attributes

Returns

a sequence containing the elements greater than or equal to circular index ''from'' extending up to (but not including) circular index ''until'' of this sequence.

Note

a slice of a circular sequence can be bigger than the size of the elements in the sequence.

Example
Seq(0, 1, 2).sliceO(-1, 4) // Seq(2, 0, 1, 2, 0)

Inherited extensions

extension [A, CC <: (SeqOps)](ring: CC[A])
def reflectAt(i: IndexO): CC[A]

Reflects the sequence to start at some circular index.

Reflects the sequence to start at some circular index.

Value parameters

i

IndexO

Attributes

Returns

a sequence consisting of all elements reversed and rotated to start at circular index ''i''.

Example
Seq(0, 1, 2).reflectAt() // Seq(0, 2, 1)
Inherited from:
TransformingOps
def rotateLeft(step: Int): CC[A]

Rotates the sequence to the left by some steps.

Rotates the sequence to the left by some steps.

Value parameters

step

the circular distance between each old and new position

Attributes

Returns

a sequence consisting of all elements rotated to the left by ''step'' places. If ''step'' is negative the rotation happens to the right.

Example
Seq(0, 1, 2).rotateLeft(1) // Seq(1, 2, 0)
Inherited from:
TransformingOps
def rotateRight(step: Int): CC[A]

Rotate the sequence to the right by some steps.

Rotate the sequence to the right by some steps.

Value parameters

step

the circular distance between each new and old position

Attributes

Returns

a sequence consisting of all elements rotated to the right by ''step'' places. If ''step'' is negative the rotation happens to the left.

Example
Seq(0, 1, 2).rotateRight(1) // Seq(2, 0, 1)
Inherited from:
TransformingOps
def startAt(i: IndexO): CC[A]

Rotates the sequence to start at some circular index.

Rotates the sequence to start at some circular index.

Value parameters

i

IndexO

Attributes

Returns

a sequence consisting of all elements rotated to start at circular index ''i''. It is equivalent to rotateLeft.

Example
Seq(0, 1, 2).startAt(1) // Seq(1, 2, 0)
Inherited from:
TransformingOps
extension [A, CC <: (SeqOps)](ring: CC[A])
def applyO(i: IndexO): A

Gets the element at some circular index.

Gets the element at some circular index.

Value parameters

i

IndexO

Attributes

Throws
java.lang.ArithmeticException

if Seq is empty

Example
Seq(0, 1, 2).applyO(3) // 0
Inherited from:
IndexingOps

Normalize a given index of a circular Seq

Normalize a given index of a circular Seq

Value parameters

i

IndexO

Attributes

Inherited from:
IndexingOps