Created
March 29, 2017 02:58
-
-
Save chadselph/520124336da7acaf1a1776c53e9cef71 to your computer and use it in GitHub Desktop.
trying to convert HList to List[LUB]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless.{::, HList, HNil} | |
import shapeless.LUBConstraint._ | |
import shapeless.ops.hlist.ToTraversable._ | |
import scala.util.Try | |
import shapeless.ops.hlist._ | |
object Path { | |
def /(s: String) = Path(PathLiteral(s) :: HNil) | |
def param[T](name: String) = PathParameter(name) | |
} | |
sealed trait PathSegment[+T] | |
case class PathLiteral(value: String) extends PathSegment[String] | |
case class PathParameter[+T](name: String) extends PathSegment[T] | |
case class Path[L <: HList : <<:[PathSegment[_]]#λ](segments: L) | |
(implicit ev: ToList[L, PathSegment[_]]) | |
{ | |
def /(literal: String) = Path(PathLiteral(literal) :: segments) | |
def /[T](param: PathParameter[T]) = Path(param :: segments) | |
override def toString: String = s"Path(${segments.toList.reverse})" | |
} | |
object Test extends App { | |
import Path.param | |
val myPath = Path / "v1" / "pets" / param[String]("name") / "pictures" | |
println(myPath) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment