[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Conventional name proposal: merge
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Fri, 14 Dec 2012 14:07:37 +0100
Whoops, I missed Michal's post.
-- Pierre-Yves
On Fri, Dec 14, 2012 at 2:05 PM, Pierre-Yves Gérardy <pygy79@gmail.com> wrote:
> In the JavaScript world, Undescore provides several functions that do
> this (in Lua syntax, even though he Lua port of Underscore lags
> severely.):
>
> t1 = {foo="Wow"}
> _.extend(t1, {foo="Glop}, ...) -- mutates t1.
>
> If you want a shallow copy, you can provide an empty table as first
> argument. They also have _.clone, for convenience.
>
> There's also _.default(). It also mutates its first argument, but
> precedence is inverted.
>
> t1 = {foo="Wow"}
> _.default(t1, {foo="Gruuu",bar="Zim!"},{bar="Drep"})
>
> t1 is now {foo="Wow",bar="Zim"}
>
> -- Pierre-Yves
>
> -- Pierre-Yves
>
>
> On Fri, Dec 14, 2012 at 7:19 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> merge(...): returns a new table containing all the pairs from all the
>> tables given as arguments. In particular, if there is only one argument,
>> returns a shallow copy. In case of duplicate keys, later values
>> replace earlier ones. Nil arguments are treated as empty tables.
>>
>> The documentation is much longer than the code!
>>