Skip to content
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

Customize string representation #38

Open
tadfisher opened this issue Nov 18, 2021 · 3 comments
Open

Customize string representation #38

tadfisher opened this issue Nov 18, 2021 · 3 comments

Comments

@tadfisher
Copy link
Collaborator

Kotlin generates a toString method for data/value classes that I'd like to override. There are a couple of particular customizations I'd like to make:

  • Redact sensitive info from being potentially logged
  • Value classes look like "Type(contents)" when I usually want just the "contents" part

So a nice option to support with #13 could be stringTemplate :: Maybe Text, which would result in a toString() override on the Kotlin backend and perhaps a CustomStringConvertible implementation on the Swift backend.

@chessai
Copy link
Collaborator

chessai commented Nov 18, 2021

Can you share (for Kotlin) what the code generated would look like?

@chessai
Copy link
Collaborator

chessai commented Nov 18, 2021

Well, after a quick Google search I can see what it would look like. How would we generate the toString implementation? Moat isn't really capable of generating term-level expressions.

@tadfisher
Copy link
Collaborator Author

How would we generate the toString implementation? Moat isn't really capable of generating term-level expressions.

Just a string template would work fine, because both Kotlin and Swift do string interpolation. So all Moat would need to generate is

override fun toString(): String = "<stringTemplate>"

and it would be on the user to pass something that makes sense in the context of the type.

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

No branches or pull requests

2 participants