[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: sunday afternoon whishlist: append/stream operator
- From: Petite Abeille <petite_abeille@...>
- Date: Tue, 01 Jun 2010 21:52:31 +0200
On Jun 1, 2010, at 9:27 PM, Oliver Schmidt wrote:
> What do you think?
Why Sunday?
What about __add?
E.g.:
local function Add( aList, aValue )
if type( aValue ) == 'table' then
for anIndex = 1, #aValue do
aList[ #aList + 1 ] = aValue[ anIndex ]
end
else
aList[ #aList + 1 ] = aValue
end
return aList
end
local function Stream( aList )
local aList = aList or {}
setmetatable( aList, { __add = Add } )
return aList
end
local aList = Stream()
aList = aList + { 'a', 'b', 'c'} + 'f' + { 'x', 'y' } + 'z'
for anIndex = 1, #aList do
print( anIndex, aList[ anIndex ] )
end
> 1 a
> 2 b
> 3 c
> 4 f
> 5 x
> 6 y
> 7 z