You could define a helper function, for example: defp map_get_any(map, keys), do: Enum.find_value(keys, &Map.get(map, &1))
That could be used like this: data |> Poison.decode! |> map_get_any(["foo", "bar"]) Michał. On 20 Mar 2017, 12:53 +0100, David Long <[email protected]>, wrote: > Hi Ben, > My issue is specific to pipes. What I'm ultimately doing is taking a JSON > object, parsing it with Poison.decode!, And then attempting to pull a single > key out, either overrideoncall or oncall. > > > On Mon, Mar 20, 2017, 7:49 AM Ben Wilson <[email protected]> wrote: > > > Can you elaborate on the code you have in mind? This sounds like a > > > general characteristic of pipes and not something specific to > > > Map.get_lazy. > > > > > > > > > On Monday, March 20, 2017 at 6:48:46 AM UTC-4, David Long wrote: > > > > That's not entirely accurate. In my case I was using a series of pipes > > > > so I did not have access to the map. My case might be very niche, > > > > though. > > > > > > > > On Mon, Mar 20, 2017, 12:44 AM José Valim > > > > <[email protected]> wrote: > > > > > The reason why get_lazy does not pass the map is because you already > > > > > have the map, since you pass it as first argument. > > > > > > > > > > On Mon, Mar 20, 2017 at 03:44 David Long <[email protected]> wrote: > > > > > > I was working on some code that would simply test if one key was in > > > > > > a map and return it's value, and otherwise return a different key's > > > > > > value. > > > > > > > > > > > > The map had a form like the following: > > > > > > > > > > > > > %{ > > > > > > > oncall: "dlong", > > > > > > > overrideoncall: "jsmith", > > > > > > > ... > > > > > > > } > > > > > > > > > > > > If there was someone overriding on call then their name would be in > > > > > > the `overrideoncall` key, otherwise the key would not be in the map. > > > > > > > > > > > > I think this could be a nice use for `Map.get_lazy`, if the > > > > > > function had the original map passed in, allowing me to write the > > > > > > code as follows: > > > > > > > > > > > > > Map.get_lazy(on_call_group, :overrideoncall, &(&1[:oncall])) > > > > > > > > > > > > Before I wrote a pull request, I thought I'd see if this is a > > > > > > feature that makes sense to others? > > > > > > -- > > > > > > 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 [email protected]. > > > > > > > > > > > > To view this discussion on the web visit > > > > > > https://groups.google.com/d/msgid/elixir-lang-core/719dc4fc-ae23-4437-b059-d91356e9b43b%40googlegroups.com. > > > > > > For more options, visit https://groups.google.com/d/optout. > > > > > -- > > > > > > > > > > > > > > > José Valim > > > > > www.plataformatec.com.br > > > > > Skype: jv.ptec > > > > > Founder and Director of R&D > > > > > -- > > > > > You received this message because you are subscribed to a topic in > > > > > the Google Groups "elixir-lang-core" group. > > > > > To unsubscribe from this topic, visit > > > > > https://groups.google.com/d/topic/elixir-lang-core/JuAZnOXpo5Q/unsubscribe. > > > > > To unsubscribe from this group and all its topics, send an email to > > > > > [email protected]. > > > > > > > > > > To view this discussion on the web visit > > > > > https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4J7dZWROSBnBU7Ayn%3DhQGphp_ciFZTRf83XscDTQQ2z3w%40mail.gmail.com. > > > > > For more options, visit https://groups.google.com/d/optout. > > > -- > > > You received this message because you are subscribed to a topic in the > > > Google Groups "elixir-lang-core" group. > > > To unsubscribe from this topic, visit > > > https://groups.google.com/d/topic/elixir-lang-core/JuAZnOXpo5Q/unsubscribe. > > > To unsubscribe from this group and all its topics, send an email to > > > [email protected]. > > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/elixir-lang-core/9f0334d6-c484-454e-8fe7-d236e2804f45%40googlegroups.com. > > > For more options, visit https://groups.google.com/d/optout. > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/CAPkhLiTqYyUahLNn%2BwGcO-bLyJHHQvapoHfX1MWwMUDCx9%2BsaQ%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/7f0ddb7d-8992-4b8d-b7ae-dec91ba6903b%40Spark. For more options, visit https://groups.google.com/d/optout.
