lua-users home
lua-l archive

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


> But your map functions do have to follow the (i,val) convention

True.  Passing everything that the iterator produces seemed the cleanest way.

> Although an adapter can be written for single-valued functions:

Other options are a "valseq" function to produce values or... use a filter:

function value(seq, f)
    local saved_key

    local function self(k, ...)
        saved_key = k
        return ...
    end
    return function(s, k)
        return self(f(s, saved_key or k))
    end
end

t = {
  aap = "noot",
  mies = "vuur",
  wim = "jet",
}

for x in seq(pairs(t)) (value) do
  print(x)
end

Bye,
Wim