On Tue, Dec 8, 2009 at 10:44 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
Nice, a well-chosen set of functionalities. I like how you've provided
some aliases.
I quote:
_.({1,2,3,4}):chain():map(function(i) return i+1
end):select(function(i) i%2 == 0 end):value()
First random observation: Lua people tend to use '_' as a throwaway
variable, in cases like 'local _,i2 = s:find('%s+')'. But it can
always be aliased if necessary.
I thought of this as I use '_' for throwaway variables myself. I couldn't think of anything better though and since this is basically a rip off of the _javascript_ library I went with it. Plus as you pointed out you can use "__ = _:no_conflict()" or whatever.
Second, support for 'string lambdas' would be cool:
_.({1,2,3,4}):chain():map '|i| i + 1' :select '|i| i%2==0': value()
There's a slight hit to compile them, but thereafter they can be
easily memoized. They don't require any syntax enhancements so David K
can only have style objections ;)
This is an interesting idea, I'd have to either:
1) insert a 'return' so it would limit the string lambda to a single _expression_
2) have a complex parser
3) require the 'return' to be explicit (e.g. map '|i| return i + 1')
I'll play around with this idea, if anybody wants to submit any code I'd be happy to take a look.
> - I'd like a nice function for dumping any object as well as a good table
> equality function
As for table comparison, this is the one I use in Penlight:
Thanks!
steve d.