All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.norbitltd.spoiwo.model.HasIndex.scala Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
package com.norbitltd.spoiwo.model

trait HasIndex[T] {
  def index(t: T): Option[Int]
}

object HasIndex {
  implicit object CellHasIndex extends HasIndex[Cell] {
    override def index(t: Cell): Option[Int] = t.index
  }
  implicit object RowHasIndex extends HasIndex[Row] {
    override def index(t: Row): Option[Int] = t.index
  }

  implicit class RichHasIndexSeq[T](indexed: Iterable[T])(implicit indexer: HasIndex[T]) {
    def maxIndex = {
      indexed.foldLeft(0) { case (maxIdx, e) => math.max(maxIdx, indexer.index(e).getOrElse(maxIdx + 1))}
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy