The value of `::` in the type parameter?

Looking at the Travis Brown blog post on Class Types and General Output , I see the following method:

  implicit def hconsParser[H: Parser, T <: HList: Parser]: Parser[H :: T] =           
   new Parser[H :: T] {
    def apply(s: String): Option[H :: T] = s.split(",").toList match {
      case cell +: rest => for {
        head <- implicitly[Parser[H]].apply(cell)
        tail <- implicitly[Parser[T]].apply(rest.mkString(","))
      } yield head :: tail
    }
  }

What is the value H :: Tin Parser[H :: T]?

Also, how does this case cell +: resthandle the case when s, that is, the input is applyempty?

+4
source share
1 answer

H :: Tis an infix type of type ::[H, T], which is HListwith a type head Hand a tail with a type T <: HList. those. we are looking Parserfor type ::[H, T].

The use of infix is ​​achieved in such a way, where it infixcan be any name:

scala> trait infix[A, B]

scala> def test[A, B](ab: A infix B) = ???
test: [A, B](ab: infix[A,B])Nothing

Also, how does this case cell +: resthandle the case when s, that is, the input is applyempty?

s - , s.split(",").toList List ​​ . case cell +: rest .

+9

Source: https://habr.com/ru/post/1649606/


All Articles