Silly question of the day: Is there a way in #scala3 to "unpack" a String at the type level ?
ie: val x: Unpack["abc"] = ('a', 'b', 'c')
-
-
Yeah I was expecting it to be feasible using a Match Type but maybe I was too optimistic :)
-
There's also scala.compiletime.ops.string.+, but I'm not sure how it uniquely deconstructs a String.
- Show replies
New conversation -
-
-
I don't know of one, though. But the macro is very easy. Something like this: def unpack[T <: Singleton & String: Type](using Quotes): Expr[List[Char]] = import quotes.reflect._ TypeRepr.of[T] match case ConstantType(StringConstant(str)) => '{ str.toList } (untested) ;)
-
Oh, and you'll also need the macro inline def unpack[T <: Singleton & String]: List[Char] = ${unpack[T]}
- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.