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

stringify_map/1 ? #11

Closed
nelsonic opened this issue May 9, 2022 · 3 comments
Closed

stringify_map/1 ? #11

nelsonic opened this issue May 9, 2022 · 3 comments
Assignees
Labels
discuss Share your constructive thoughts on how to make progress with this issue enhancement New feature or request help wanted Extra attention is needed technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

nelsonic commented May 9, 2022

I've found myself wanting to Logger.info("map: #{map}") a few times and not being able to ...
Considered using Jason.encode!/1 https://github.com/michalmuskala/jason#basic-usage
but would much prefer to have a lightweight solution that just makes a single string not a string with nested/escaped strings ...

iex(1)> Jason.encode!(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"})
"{\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}"

vs:

iex(1)> Useful.stringify_map(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"})
"age:44, name:Steve Irwin, nationality: Australian"

I don't want JSON. I just want to see what's inside the Map without having to do any gymnastics.

@SimonLab thoughts? Have you needed something like this in your recent Elixir work? 💭

@nelsonic nelsonic added enhancement New feature or request help wanted Extra attention is needed discuss Share your constructive thoughts on how to make progress with this issue technical A technical issue that requires understanding of the code, infrastructure or dependencies labels May 9, 2022
@SimonLab
Copy link
Member

SimonLab commented May 9, 2022

Could we use inspect?

%{a: 1} |> inspect() |> Logger.debug()

see: https://stackoverflow.com/questions/35008884/how-to-log-a-map-struct-in-elixir

@nelsonic
Copy link
Member Author

nelsonic commented May 9, 2022

Definitely! That's a good short-term solution and less to type. Good call.

@nelsonic
Copy link
Member Author

This was shipped: https://hexdocs.pm/useful/Useful.html#stringify_map/1
But not documented in the README.md
So I've added the docs via this PR: #26

SimonLab added a commit that referenced this issue Oct 17, 2022
PR: Add usage example of `stringify_map/1` to `README.md` closes #11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Share your constructive thoughts on how to make progress with this issue enhancement New feature or request help wanted Extra attention is needed technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
None yet
Development

No branches or pull requests

2 participants