Skip to content

Conversation

road21
Copy link
Contributor

@road21 road21 commented Aug 27, 2025

There already are methods toArray, toList for NamedTuple for collecting elements into collections.
I would like to add method toSeqMap where keys are names of the elements.

For example:

(x = 1, y = true).toSeqMap // SeqMap("x" -> 1, "y" -> true)

One obvious usage of this method is debugging code with named tuples (standard toString method doesn't show names):

println((x = 1, y = true)) // prints (1, true)
println((x = 1, y = true).toSeqMap) // prints SeqMap(x -> 1, y -> true)

@road21 road21 requested a review from a team as a code owner August 27, 2025 12:50
@Gedochao Gedochao requested a review from aherlihy August 27, 2025 13:03
@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from e908ff4 to 0387869 Compare August 27, 2025 16:49
@He-Pin
Copy link
Contributor

He-Pin commented Sep 1, 2025

Will there be a toListMap

@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from 0d8a36c to 37b4759 Compare September 2, 2025 08:45
@road21
Copy link
Contributor Author

road21 commented Sep 2, 2025

Will there be a toListMap

I think toListMap is enough, fixed to toListMap

@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from 37b4759 to 25bf111 Compare September 2, 2025 08:47
@road21
Copy link
Contributor Author

road21 commented Sep 2, 2025

@aherlihy could you please take a look?

@road21 road21 force-pushed the feature-named-tuples-to-map-std branch 2 times, most recently from c89ac35 to e5495a0 Compare September 9, 2025 07:09
@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from e5495a0 to f884f31 Compare September 18, 2025 06:30
@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from f884f31 to 1253c3d Compare September 23, 2025 15:21
@Gedochao Gedochao requested a review from bracevac September 24, 2025 05:53
@aherlihy
Copy link
Contributor

@road21 Is this ready for review? Once its rebased I will take a look.

@aherlihy
Copy link
Contributor

Also, at first glance, you should abstract over the implementation and return a Map (not ListMap), and name it toMap, as we do not want to add something to the standard library and be required to keep the implementation forever.

@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from 1253c3d to f0b89fe Compare September 24, 2025 12:08
@road21
Copy link
Contributor Author

road21 commented Sep 24, 2025

@road21 Is this ready for review? Once its rebased I will take a look.

Yes, rebased

Also, at first glance, you should abstract over the implementation and return a Map (not ListMap), and name it toMap, as we do not want to add something to the standard library and be required to keep the implementation forever.

What about toSeqMap: SeqMap[String, Tuple.Union[V]] then?
I would like to keep the order of elements

@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from 2532d5d to a94358c Compare September 29, 2025 09:15
@road21
Copy link
Contributor Author

road21 commented Sep 29, 2025

@road21 Is this ready for review? Once its rebased I will take a look.

Please, take a look. I have fixed method to SeqMap

@road21 road21 force-pushed the feature-named-tuples-to-map-std branch 2 times, most recently from 910a534 to 6f0d4cc Compare October 12, 2025 17:49
@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from 6f0d4cc to 254aa5d Compare October 15, 2025 10:58
@Gedochao Gedochao requested a review from bracevac October 15, 2025 12:56
Copy link
Contributor

@bracevac bracevac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The failing CI test is unrelated. Please also squash the commits. It's a small change set.

@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from d9da876 to 481ed88 Compare October 16, 2025 07:26
@road21 road21 force-pushed the feature-named-tuples-to-map-std branch from 481ed88 to 388b7e6 Compare October 16, 2025 07:39
@hamzaremmal
Copy link
Member

I would like to keep the order of elements

May I ask why?

@road21
Copy link
Contributor Author

road21 commented Oct 16, 2025

May I ask why?

Just because we have an order and I don't see any downsides of toSeqMap instead of toMap.
If user will need list of pairs (field name, field value) - toSeqMap fits.
I don't have any realistic example yet.
But I can change it back to toMap if you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants