Skip to content

[WIP] Add methods to abstract over structure of case classes #1346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

felixmulder
Copy link
Contributor

@felixmulder felixmulder commented Jun 30, 2016

Inspired by #1341, I decided to take a crack at improving case classes. These commits add two members to case classes:

  • def fields: List[String]
  • def toMap: Map[String, Any]

I think it is important to have a good way of abstracting over the members of case classes, this provides just that. One drawback to having this signature in the toMap method is that we loose type information. Ideally something like an HMap could be used here to retain type information.

There's room for improvement in this implementation as well - for instance def fields could of course be a @static val fields in the companion instead.

These two functions could in turn be used to improve the toString capabilities of case classes as well as various forms of pickling. Let me know your thoughts on this - if it feels like a step in the right direction, I wouldn't mind spending some time on this.

@odersky
Copy link
Contributor

odersky commented Jul 1, 2016

I see lots of ideas for improvements to case classes. Instead of trying to do this piece-wise I would prefer to have a very comprehensive SIP detailing how case classes should in the future support generic programming. I'll open an issue for this to serve as a place where discussions can take place.

@felixmulder
Copy link
Contributor Author

Sounds good :)

@aisven
Copy link

aisven commented Apr 6, 2018

@odersky or someone else: Please provide the link to the new issue where this is/was being discussed further.

@Blaisorblade
Copy link
Contributor

@sourcekick I can't read Martin's mind, but the next issue, #1347, appears highly relevant.

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.

4 participants