Hi,

Would it make sense introducing a trailing bang version mirroring the
existing Map.take/2? It would behave the same but fail with a KeyError on a
missing key instead of simply ignoring it.

To give some context, I've lately found myself writing things like `%{foo:
data.foo, bar: data.bar, ...}` quite frequently, a typical use case being
to dump only some fields from a map or struct into a JSON payload or
Elasticsearch. While it's tempting to refactor those using `Map.take/2`, it
feels best to fail frankly than omitting fields accidentally in order to
avoid potential bugs.

I suppose we would also introduce Keyword.take!/2 for consistency if we
move forward.

What do you think?

Cheers,
Sabiwara

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CANnyohYswjnXFqA79%2BP7cEfd5%2Bg%2BZsJeBHWf5M3kSi4TBrw0NQ%40mail.gmail.com.

Reply via email to