lua-users home
lua-l archive

Re: iterator sequences (was: Standard libraries)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jan 1, 2010, at 7:42 AM, Wim Couwenberg wrote:
> function seq(f, state, key)
> local function self(s, k, ...)
> if type(s) == "function" then
> f = s(self, f, k, ...) or f
> return self, state, key
> else
> return f(s, k)
> end
> end
> return self, state, key
> end
Could this be rewritten as:
	function seq( f, state, key )
		local function self( s, k, ... )
			if s == state then
				return f( s, k )
			else
				f = s( self, f, k, ... ) or f
				return self, state, key
			end
		end
		return self, state, key
	end
The assumption here being that the state isn't going to be used as a modification operator for the sequence. Is that more or less of a potential problem than the assumption that the state won't be a function?
The explicit iterate change I proposed would also potentially apply but I left it out for clarity.
Mark

AltStyle によって変換されたページ (->オリジナル) /