[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Map and filter without intermediate tables
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 7 Jun 2012 13:30:08 +0200
On Thu, Jun 7, 2012 at 1:06 PM, Geoff Leyland <geoff_leyland@fastmail.fm> wrote:
> Yes, but if you have a function generating a sequence and a series of sequence processors that might do things like map or filter that sequence, then you might consider avoiding intermediate tables, since there was never a table in the first place.
That was the idea behind pl.seq
https://github.com/stevedonovan/Penlight/blob/master/lua/pl/seq.lua
E.g,
> f = stringio.open 'one\n\ntwo\nthree'
> seq(f:lines()):filter('~','^t'):upper():printall()
TWO THREE
But I've never bothered to check the speed - I suppose the thing about
iterators is that they are 'lazy lists', potentially infinite.
> seq(function() return math.random(1,10) end):take(5):printall()
4 9 9 8 2
Personally, I prefer method chaining to functional application, since
my brain tends to work best left-to-right.
steve d.