IndexingOps

io.github.scala_tessella.ring_seq.IndexingOps
trait IndexingOps

Provides indexing operations for a Seq considered circular.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object SymmetryOps
trait SlicingOps
trait IteratingOps
trait ComparingOps
trait NecklaceOps
object RingSeq
trait SymmetryOps
Show all

Members list

Type members

Types

type Index = Int

For improved readability, the index of a Seq.

For improved readability, the index of a Seq.

Attributes

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

Extensions

Extensions

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

Normalize a given index of a circular Seq

Normalize a given index of a circular Seq

Value parameters

i

IndexO

Attributes

def indexOfO(elem: A, from: IndexO = ...): Index

Finds the circular index of the first element equal to a given value, searching circularly from a given circular index (the circular version of indexOf).

Finds the circular index of the first element equal to a given value, searching circularly from a given circular index (the circular version of indexOf).

The whole ring is searched, wrapping past the end back to the start.

Value parameters

elem

the element value to search for

from

IndexO

Attributes

Returns

the Index in [0, size) of the first element found at or after circular index ''from'', or -1 if the element is not in the sequence.

Example
Seq(0, 1, 2).indexOfO(0, 1) // 0
def liftO(i: IndexO): Option[A]

Optionally gets the element at some circular index (the circular version of lift).

Optionally gets the element at some circular index (the circular version of lift).

Since every circular index is valid on a non-empty sequence, this returns None only when the sequence is empty.

Value parameters

i

IndexO

Attributes

Example
 Seq(0, 1, 2).liftO(3)   // Some(0)
 Seq.empty[Int].liftO(0) // None