DR
Size: a a a
DR
Е
DR
DR
fn(key, %{^key => value})
->DR
Е
Е
DR
key = :test
fn(key, %{^key => value}) -> value end
iex(4)> v.(:foo, %{test: 1})
1
Е
Е
DR
Е
Е
DR
DR
when my_function(...)
- не поддерживается. И у того и другого есть технические причины, почему сделано именно так.DR
fn(key, %{^key := value})
- оно помимо этого уже работает и семантически по-другому.DR
def test(map, key) when :erlang.is_map_key(key, map), do: {:ok, :erlang.map_get(key, map)}
def test(_, _), do: {:error, :not_found}
DR
Yes, we should. There are things that can’t be expressed with the other proposals (or any other way in a guard for that matter), most notably:
def check_key(map, key) when is_list(map_get(map, key)), do: ...
It’s effectively implementing the def foo(key, %{key => value}) ... that is such a frequent request - now we’d have a way to do this.
DR
def foo(key, %{key => value})
=> нельзя сделать через новые guard-ы, а соответственно требует всё равно какой-нибудь эмуляции.DR