I would appreciate hearing your thoughts on https://github.com/hzamani/synex
. It has two macros: keys and params, first one for expansion of atom-value 
pairs in keyword lists, maps and structs, and other for expansion of 
string-value pairs in maps. Both of them have variable pinning and map 
update support and params supports nested maps:

iex> params(%{a => %{b, c}}) = %{"a" => %{"b" => 2, "c" => 3}}
iex> a
%{"b" => 2, "c" => 3}
iex> c
3

Hassan

On Wednesday, February 17, 2016 at 1:29:31 PM UTC+3:30, Jaap Frolich wrote:
>
> Very nice Johan,
>
> Love the power of macros. Is there any resolution if this will make the 
> standard library? I have a lot of repetition in my maps as well in my 
> current app, and this is one of the things I like in ES6 that I really miss 
> in Elixir (mostly it is of course the other way around ;)).
>
> Cheers,
>
> Jaap
>
> On Monday, August 10, 2015 at 4:57:02 PM UTC+8, Johan Wärlander wrote:
>>
>> After playing around a bit with the ~m sigil, I proposed a couple of 
>> updates (one which touched on work that Andrea had alredy done, but with a 
>> twist); short_maps now support the following:
>>
>> # Equality checks
>> foo = 1
>> bar = 2
>> ~m(foo bar)a == %{foo: 1, bar: 2} #=> true
>>
>> # Matching
>> ~m(foo bar)a = %{foo: 12, bar: "baaz"}
>> foo #=> 12
>>
>> # Pinning (NEW)
>> foo = 1
>> ~m(^foo bar)a = %{foo: 1, bar: "baaz"} #=> %{foo: 1, bar: "baaz"}
>> ~m(^foo bar)a = %{foo: 5, bar: "baaz"} #=> MatchError
>>
>> # Structs, when first word starts with '%' (NEW)
>> defmodule Foo do
>>   defstruct bar: nil
>> end
>> ~m(%Foo bar)a = %Foo{bar: "baaz"}
>> bar #=> "baaz"
>>
>> For anyone else interested, please do get the latest version from 
>> Andrea's repository (https://github.com/whatyouhide/short_maps), then 
>> play around with it and see how it feels.
>>
>> On Friday, June 19, 2015 at 12:02:36 PM UTC+2, Andrea Leopardi wrote:
>>>
>>> I stood against the %{foo, bar, baz} syntax and deemed that too 
>>> implicit, but I'm in favour of a possible ~m sigil. I think it may 
>>> still be a bit implicit, but I can see it would make code much more concise 
>>> in a lot of situations. I took a stab at it and wrote a simple 
>>> implementation for such sigil, here 
>>> <https://github.com/whatyouhide/short_maps>. We can try it out and see 
>>> if we like it (and please, have a look at the implementation as well as I'm 
>>> not sure it's bulletproof).
>>>
>>>
>>>
>>> On Sunday, May 31, 2015 at 12:19:46 PM UTC+2, Devin Torres wrote:
>>>>
>>>> Taking a pretty cool page out of ES6:
>>>>
>>>> # If `method`, `url`, `headers`, and `payload` are already bound
>>>> %Request{method, url, headers, payload}
>>>>
>>>> # If e.g. `payload` hasn't been bound yet
>>>> %Request{method, url, headers, payload: get_payload()}
>>>>
>>>

-- 
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/b4682fa4-8935-4e87-85ec-b5bb4dcfd551%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to