We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Unlifted.unapply
1 parent c372fa1 commit 7232231Copy full SHA for 7232231
library/src/scala/quoted/Unlifted.scala
@@ -27,12 +27,13 @@ object Unlifted {
27
* }
28
* ```
29
*/
30
- def unapply[T](exprs: Seq[Expr[T]])(using unlift: Unliftable[T], qctx: Quotes): Option[Seq[T]] =
31
- exprs.foldRight(Option(List.empty[T])) { (elem, acc) =>
32
- (elem, acc) match {
33
- case (Unlifted(value), Some(lst)) => Some(value :: lst)
34
- case (_, _) => None
35
- }
36
+ def unapply[T](exprs: Seq[Expr[T]])(using Unliftable[T])(using Quotes): Option[Seq[T]] =
+ val builder = Seq.newBuilder[Seq[T]]
+ val iter = exprs.iterator
+ while iter.hasNext() do
+ iter.next() match
+ case Unlifted(value) => builder += value
+ case _ => return None
37
+ Some(builder.result)
38
39
}
0 commit comments