Step by step:
Method
on object JsPath
val path1: JsPath = JsPath "from_user_name"
val path2: JsPath = JsPath "text"
Method read
on object of type JsPath
val reads1: Reads[String] = path1.read[String]
val reads2: Reads[String] = path2.read[String]
There is no method ~
in Reads
, but there is such method in FunctionalBuilderOps
and there is an implicit conversion from M[T]
to FunctionalBuilderOps[M[_], T]
in play.api.libs.functional.syntax
- toFunctionalBuilderOps
.
val reads1FunctionalBuilderOps: FunctionalBuilderOps[Reads, String] =
toFunctionalBuilderOps(reads1)
val canBuild2: CanBuild2[String, String] = reads1FunctionalBuilderOps.~(reads2)
Tweet.apply _
is a scala syntax to create a FunctionN
using method with N
arguments:
val func: (String, String) => Tweet = Tweet.apply _
There is an apply
method in CanBuild2[A, B]
. It accepts (A, B) => C
and returns Reads[C]
(in this case):
implicit val tweetReads: Reads[Tweet] = canBuild2.apply(func)
Actually there are also implicit parameters in JsPath#read
, toFunctionalBuilderOps
and CanBuild2#apply
methods. With that parameters:
val reads1: Reads[String] = path1.read[String](Reads.StringReads)
...
val reads1FunctionalBuilderOps: FunctionalBuilderOps[Reads, String] =
toFunctionalBuilderOps(reads1)(
functionalCanBuildApplicative(
Reads.applicative(JsResult.applicativeJsResult)))
...
implicit val tweetReads: Reads[Tweet] =
canBuild2.apply(func)(functorReads)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…