forked from japgolly/scalajs-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-px
executable file
·60 lines (52 loc) · 1.76 KB
/
gen-px
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/env scala
// vim: set ft=scala :
val comma = ", "
def T(i: Int) = (64+i).toChar.toString
locally {
var ra = Seq.empty[String]
for (i <- (0 to 22)) {
def A(j: Int) = ('A'+j).toChar.toString
def a(j: Int) = ('a'+j).toChar.toString
val As = (0 until i) map A
val as = (0 until i) map a
val Ac = As mkString ","
val ac = as mkString ","
val AZ = (if (i == 0) "" else Ac+",") + "Z"
val ScalaFn = s"($Ac)=>Z"
// val ScalaFn = s"scala.runtime.AbstractFunction$i[$AZ]"
val JsFn = s"js.Function$i[$AZ]"
ra :+= s"""
| implicit def scalaFn$i[$AZ]: Extract[$ScalaFn] =
| Extract[$ScalaFn](px => ($ac) => px.value()($ac))
|
| implicit def jsFn$i[$AZ]: Extract[$JsFn] =
| Extract[$JsFn](px => ($ac) => px.value()($ac))
""".stripMargin
}
println("object Extract {")
println(ra.mkString("").replaceAll("\\s+$", ""))
println(" }")
println()
}
locally {
var ra = Seq.empty[String]
for (i <- (2 to 22)) {
// def m (f: Int => String): List[String] = (1 to a).toList.map(f)
// def mc(f: Int => String): String = m(f).mkString(comma)
// def mt(f: Int => String): String = m(f).mkString("(",comma,")")
def A(j: Int) = ('A'+j).toChar.toString
def a(j: Int) = ('a'+j).toChar.toString
val As = (0 until i) map A
val as = (0 until i) map a
val Ac = As mkString ","
val ac = as mkString ","
def args = (0 until i).map(j => s"p${('a'+j).toChar}:Px[${('A'+j).toChar}]") mkString ", "
def exts = as.map(a => s"$a<-p$a") mkString ";"
ra :+= s"""
| def apply$i[$Ac,Z]($args)(z:($Ac)=>Z): Px[Z] =
| for {$exts} yield z($ac)
""".stripMargin
}
print(ra mkString "")
println()
}