Skip to content

Commit 92d3267

Browse files
liufengyunG1ng3r
authored andcommitted
Add test
1 parent b3c6141 commit 92d3267

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import scala.collection.mutable
2+
3+
object Test:
4+
type JsonPrimitive = String | Int | Double | Boolean | None.type
5+
6+
type Rec[JA[_], JO[_], A] = A match
7+
case JsonPrimitive => JsonPrimitive | JA[Rec[JA, JO, JsonPrimitive]] | JO[Rec[JA, JO, JsonPrimitive]]
8+
case _ => A | JA[Rec[JA, JO, A]] | JO[Rec[JA, JO, A]]
9+
10+
type Json = Rec[[A] =>> mutable.Buffer[A], [A] =>> mutable.Map[String, A], JsonPrimitive]
11+
12+
type JsonObject = mutable.Map[String, Json]
13+
14+
type JsonArray = mutable.Buffer[Json]
15+
16+
def encode(x: Json): Int = x match
17+
case str: String => 1
18+
case b: Boolean => 2
19+
case i: Int => 3
20+
case d: Double => 4
21+
case arr: JsonArray => 5 // error
22+
case obj: JsonObject => 6 // error
23+
case _ => 7

0 commit comments

Comments
 (0)