File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
package scala .quoted
2
2
3
+ import scala .reflect .ClassTag
4
+
3
5
/** A typeclass for types that can be turned to `quoted.Expr[T]`
4
6
* without going through an explicit `'{...}` operation.
5
7
*/
@@ -43,6 +45,13 @@ object Liftable {
43
45
}
44
46
}
45
47
48
+ given [T : Type : Liftable : ClassTag ] as Liftable [IArray [T ]] = new Liftable [IArray [T ]] {
49
+ def toExpr (iarray : IArray [T ]): given QuoteContext => Expr [IArray [T ]] = ' { // TODO specialize
50
+ val array = new Array [T ]($ {Liftable_Int_delegate .toExpr(iarray.length)})(ClassTag ($ {ClassIsLiftable .toExpr(the[ClassTag [T ]].runtimeClass)}))
51
+ $ { Expr .block(List .tabulate(iarray.length)(i => ' { array($ {Liftable_Int_delegate .toExpr(i)}) = $ {the[Liftable [T ]].toExpr(iarray(i))} }), ' { array.asInstanceOf [IArray [T ]] }) }
52
+ }
53
+ }
54
+
46
55
given [T : Type : Liftable ] as Liftable [List [T ]] = new Liftable [List [T ]] {
47
56
def toExpr (x : List [T ]): given QuoteContext => Expr [List [T ]] = x match {
48
57
case x :: xs => ' { ($ {this .toExpr(xs)}).:: [T ]($ {the[Liftable [T ]].toExpr(x)}) }
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ object Test {
35
35
list.unrolledFoldLeft[Int ](0 )(' { (acc : Int , x : Int ) => acc + x }).show
36
36
list.unrolledForeach(' { (x : Int ) => println(x) }).show
37
37
38
+ val iarray : IArray [Int ] = IArray (1 , 2 , 3 )
39
+ val liftedIArray : Expr [IArray [Int ]] = iarray
40
+
38
41
println(" quote lib ok" )
39
42
}
40
43
}
@@ -120,11 +123,5 @@ package liftable {
120
123
}
121
124
}
122
125
123
- object Arrays {
124
- implicit def ArrayIsLiftable [T : Liftable ](implicit t : Type [T ], ct : Expr [ClassTag [T ]]): Liftable [Array [T ]] = new Liftable [Array [T ]] {
125
- def toExpr (arr : Array [T ]) = ' { new Array [$t]($ {arr.length})($ct) }
126
- }
127
- }
128
-
129
126
}
130
127
}
You can’t perform that action at this time.
0 commit comments