This can be accomplished by using a `with` in which the `else` clause is the
good result. Readability is up for debate of course.
with :error <- Map.fetch(states, abbreviation), do: {:error, "State not found"}
-Greg Vaughn
> On Jan 26, 2021, at 3:50 PM, Jonathan Arnett wrote:
>
> One
One potential benefit to a Map.fetch/3 command that wasn't considered is
that it could help users define more specific error types. There's a
loose convention to use {:ok, val} | :error | {:error, reason} as a
"result" type in Elixir (analogous to Rust's Option and Result or
Haskell's Maybe
PR: https://github.com/elixir-lang/elixir/pull/10674
poniedziałek, 25 stycznia 2021 o 13:11:03 UTC+1 woj...@wojtekmach.pl
napisał(a):
> On 25 Jan 2021, at 11:40, Boris Kuznetsov wrote:
>
> Recompilation (and delay) on every new run seems like a major issue.
>
> Probably, if you call
+1 for the proposal
+1 for including package version/additional options in cache location
I often find myself wanting to demonstrate a pattern or debug something
outside of the context of whatever full application I'm currently working
on, so this would be super useful. I like low-friction, so
Thanks, I was not aware of that.
On Tuesday, January 26, 2021 at 9:48:23 AM UTC+1 jean.pa...@gmail.com wrote:
> Hello,
> I think you're looking for `.get_lazy/3` functions.
>
> Best regards,
> Jean
>
>
> Le mardi 26 janvier 2021 à 00:47 -0800, Paweł Urbanek a écrit :
>
> Looks like get does not
Hello,
I think you're looking for `.get_lazy/3` functions.
Best regards,
Jean
Le mardi 26 janvier 2021 à 00:47 -0800, Paweł Urbanek a écrit :
> Looks like get does not evaluate the fallback function:
>
> Keyword.get([{:a, 1}], :b, fn () -> 2 + 2 end) =>
> #Function<45.97283095/0 in
Looks like get does not evaluate the fallback function:
Keyword.get([{:a, 1}], :b, fn () -> 2 + 2 end) => #Function<45.97283095/0
in :erl_eval.expr/5>
Maybe fetch!/3 could work like that?
Keyword.fetch!([{:a, 1}], :b, fn () -> 2 + 2 end) => 4
On Tuesday, January 26, 2021 at 9:40:13 AM UTC+1
Hello,
There is Map.get/3 already, how would this differ?
Best
Adam
On Tue, 26 Jan 2021 at 08:38, Paweł Urbanek
wrote:
>
> I'd like to propose extending the API for Keyword and Map, fetch! method:
>
> Map.fetch!(%{a: 1}, :b, 2) => 2
> Keyword.fetch!([a: 1], :b, 2) => 2
>
> Third argument
I'd like to propose extending the API for Keyword and Map, fetch! method:
Map.fetch!(%{a: 1}, :b, 2) => 2
Keyword.fetch!([a: 1], :b, 2) => 2
Third argument represents value which will be returned in case the
requested key is missing. Optionally maybe it could also accept the
function which is