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

checklist.ToMessage.scala Maven / Gradle / Ivy

There is a newer version: 0.5.1
Show newest version
package checklist

abstract class ToMessage[A] {
  def toError(value: A): Message
  def toWarning(value: A): Message
}

object ToMessage {
  implicit val stringToMessage: ToMessage[String] =
    new ToMessage[String] {
      def toError(message: String) = ErrorMessage(message)
      def toWarning(message: String) = WarningMessage(message)
    }

  implicit def prefixPairToMessage[P: PathPrefix](implicit prefix: PathPrefix[P]): ToMessage[(P, String)] =
    new ToMessage[(P, String)] {
      def toError(pair: (P, String)) = ErrorMessage(pair._2, prefix.path(pair._1))
      def toWarning(pair: (P, String)) = WarningMessage(pair._2, prefix.path(pair._1))
    }

  implicit def pathPairToMessage(implicit path: Path): ToMessage[(Path, String)] =
    new ToMessage[(Path, String)] {
      def toError(pair: (Path, String)) = ErrorMessage(pair._2, pair._1)
      def toWarning(pair: (Path, String)) = WarningMessage(pair._2, pair._1)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy