1

i am studying scala and have been trying to learn as much as i can. After reading the scala programming book i am reading the source code of several projects while trying some examples myself.

I am really struggling to understand what this method does. I understand that this defines a Json value such as type : value or something.

And also it expects a parametrized T that is a subtype of Product (<:), the way it uses the hashtags is completely magic to me. I cannot fathom its meaning.

def jsonFormat1[[#P1 :JF#], T <: Product :ClassManifest](construct: ([#P1#]) => T): RootJsonFormat[T] = {
    val Array([#p1#]) = extractFieldNames(classManifest[T])
    jsonFormat(construct, [#p1#])
}

Here is the Full Source for the trait, you might need it to fully understand

PS: This example is taken from project spray-json.

Rafael Saraiva
  • 848
  • 1
  • 10
  • 22
  • 3
    This isn't valid scala code. As you can see, it's **template** for scala code. They probably do some pre-processing on it. – Daniel Shin Nov 25 '15 at 13:35
  • Oh god.. I spent hours searching for this syntax trying to validate this kind of parametrization. I feel kinda dumb now.. – Rafael Saraiva Nov 25 '15 at 13:40
  • @DanielShin What kind of processing is done to this file? is this called from other file? Is this parsed? is this converted to a real trait ? Sorry if i am just dumping questions now :> – Rafael Saraiva Nov 25 '15 at 13:42
  • 2
    This is not standard Scala. You can see in the sbt configuration that `sbt-boilerplate` plugin is used. This plugin adds template language (with the hashtags) to be able to write code for tuples and functions 1..22 with no boilerplate – Vered Rosen Nov 25 '15 at 13:44
  • @VeredRosen you are right. [In the project](https://github.com/sbt/sbt-boilerplate) it is possible to see that indeed the syntax matches. – Rafael Saraiva Nov 25 '15 at 13:48

0 Answers0