Few things II

Chris Nicholson-Sauls ibisbasenji at gmail.com
Tue Aug 7 14:53:05 PDT 2007


Oskar Linde wrote:
> Secondly, I have really grown to like the way of chaining functions on 
> arrays. The function call order and the data flow is read left to right. 
> An example from my own code:
> 
> references ~= refs
>     .splitIter()
>     .filterIter((char[] c) { return c.length > 2; })
>     .map((char[] c) { return a[1..$-1]; });
> 
> Writing this as:
> 
> references ~= map(filterIterate(refs.splitIterate(),
>                                 (char[] c) { return c.length > 2; }),
>                   (char[] c) { return a[1..$-1]; });
> 
> Is both much harder to read and parse (to me atleast) and also hard to 
> indent in any meaningful way.
> 

Agreed.  Incidentally, consider this little thing I did in Ruby a few 
weeks back as an answer to a programming challenge (hey, technically 
just two lines):

#  haystack = (
#          master = IO.read('wordlist.txt').split
#      ).collect {|word| word.split(//).sort!.join }
#
#  File.new('result.txt','w').puts(
#      (IO.read('input.txt').split)
#      .collect {|word  | word.split(//).sort!.join      }
#      .collect {|needle| master[haystack.index(needle)] }
#      .join(',')
#  )

We can actually come quite close to this in D.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list