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

caseapp.core.commandparser.ConsCommandParser.scala Maven / Gradle / Ivy

There is a newer version: 2.0.0-M8
Show newest version
package caseapp.core.commandparser

import caseapp.core.parser.Parser
import shapeless.{:+:, Coproduct, Inl, Inr}

final case class ConsCommandParser[H, T <: Coproduct](
  name: String,
  parser: Parser[H],
  tail: CommandParser[T]
) extends CommandParser[H :+: T] {

  private val tail0 = tail.map[H :+: T](Inr(_))

  def get(command: String): Option[Parser[H :+: T]] =
    if (command == name)
      Some(parser.map(h => Inl(h)))
    else
      tail0.get(command)

  def mapHead[I](f: H => I): CommandParser[I :+: T] =
    map {
      case Inl(h) => Inl(f(h))
      case Inr(t) => Inr(t)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy