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

caseapp.core.complete.CompletionItem.scala Maven / Gradle / Ivy

package caseapp.core.complete

import dataclass.data

@data class CompletionItem(
  value: String,
  description: Option[String] = None,
  extraValues: Seq[String] = Nil
) {
  def values: Seq[String] = value +: extraValues

  def withPrefix(prefix: String): Option[CompletionItem] =
    if (prefix.isEmpty) Some(this)
    else {
      val updatedValues = values.filter(_.startsWith(prefix))
      if (updatedValues.isEmpty) None
      else {
        val item = CompletionItem(values.head, description, values.tail)
        Some(item)
      }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy