Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import shapeless._
- import syntax.sized._
- implicit def _0SizedToHList[T](sz: Sized[IndexedSeq[T], Nat._0]) = new {
- def toHList = {
- val IndexedSeq(a1) = sz.unsized
- a1 :: HNil
- }
- }
- implicit def _1SizedToHList[T](sz: Sized[IndexedSeq[T], Nat._1]) = new {
- def toHList = {
- val IndexedSeq(a1) = sz.unsized
- a1 :: HNil
- }
- }
- implicit def _2SizedToHList[T](sz: Sized[IndexedSeq[T], Nat._2]) = new {
- def toHList = {
- val IndexedSeq(a1, a2) = sz.unsized
- a1 :: a2 :: HNil
- }
- }
- implicit def _3SizedToHList[T](sz: Sized[IndexedSeq[T], Nat._3]) = new {
- def toHList = {
- val IndexedSeq(a1, a2, a3) = sz.unsized
- a1 :: a2 :: a3 :: HNil
- }
- }
- implicit def _4SizedToHList[T](sz: Sized[IndexedSeq[T], Nat._4]) = new {
- def toHList = {
- val IndexedSeq(a1, a2, a3, a4) = sz.unsized
- a1 :: a2 :: a3 :: a4 :: HNil
- }
- }
- def readAttributes[N <: Nat](node: xml.Node, attrs: Sized[IndexedSeq[String], N])
- (implicit toInt : shapeless.ops.nat.ToInt[N]): Option[Sized[IndexedSeq[String], N]] = {
- attrs.map(node.attribute).collect({case Some(s) => s.mkString}).sized[N]
- }
- val node = <Node title = "Title" author = "Author" price = "50"></Node>
- val funcs3 = ((s: String) => s.length > 0,
- (s: String) => s.toUpperCase,
- (s: String) => s.toInt)
- val a3 = readAttributes(node, Sized("title", "author", "price"))
- println(a3.map(args => HList(funcs3) zipApply args.toHList tupled)) // Some((true,AUTHOR,50))
- val funcs2 = ((s: String) => s.length > 0,
- (s: String) => s.toInt)
- val a2 = readAttributes(node, Sized("title", "price"))
- println(a2.map(args => HList(funcs2) zipApply args.toHList tupled)) // Some((true,50))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement