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

ammonite.repl.api.History.scala Maven / Gradle / Ivy

package ammonite.repl.api

import scala.collection.generic.CanBuildFrom
import scala.collection.{IndexedSeqLike, mutable}


class History(s: Vector[String])
extends IndexedSeq[String]
with IndexedSeqLike[String, History] {
  def length: Int = s.length
  def apply(idx: Int): String = s.apply(idx)
  override def newBuilder = History.builder
}

object History{
  def builder = new mutable.Builder[String, History] {
    val buffer = mutable.Buffer.empty[String]
    def +=(elem: String): this.type = {buffer += elem; this}

    def result(): History = new History(buffer.toVector)

    def clear(): Unit = buffer.clear()
  }
  implicit def cbf = new CanBuildFrom[History, String, History]{
    def apply(from: History) = builder
    def apply() = builder
  }
  implicit def toHistory(s: Seq[String]): History = new History(s.toVector)
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy