|
1 | 1 | package scala
|
2 | 2 | import compiletime.ops.boolean.*
|
3 | 3 | import compiletime.summonAll
|
| 4 | +import collection.immutable.ListMap |
4 | 5 |
|
5 | 6 | import language.experimental.captureChecking
|
6 | 7 |
|
@@ -31,7 +32,7 @@ object NamedTuple:
|
31 | 32 | import NamedTupleDecomposition.{Names, DropNames}
|
32 | 33 | export NamedTupleDecomposition.{
|
33 | 34 | Names, DropNames,
|
34 |
| - apply, size, init, head, last, tail, take, drop, splitAt, ++, map, reverse, zip, toList, toArray, toIArray, toMap |
| 35 | + apply, size, init, head, last, tail, take, drop, splitAt, ++, map, reverse, zip, toList, toArray, toIArray, toListMap |
35 | 36 | }
|
36 | 37 |
|
37 | 38 | extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V])
|
@@ -210,12 +211,12 @@ object NamedTupleDecomposition:
|
210 | 211 | /** An immutable array consisting of all element values */
|
211 | 212 | inline def toIArray: IArray[Object] = x.toTuple.toIArray
|
212 | 213 |
|
213 |
| - /** An immutable map consisting of all element values. |
| 214 | + /** An immutable map consisting of all element values preserving an order of fields. |
214 | 215 | * Keys are the names of the elements.
|
215 | 216 | */
|
216 |
| - inline def toMap: collection.immutable.Map[String, Tuple.Union[V]] = |
| 217 | + inline def toListMap: ListMap[String, Tuple.Union[V]] = |
217 | 218 | inline compiletime.constValueTuple[N].toList match
|
218 |
| - case names: List[String] => names.lazyZip(x.toList).toMap |
| 219 | + case names: List[String] => ListMap.from(names.zip(x.toList)) |
219 | 220 | end extension
|
220 | 221 |
|
221 | 222 | /** The names of a named tuple, represented as a tuple of literal string values. */
|
|
0 commit comments