[rust-dev] Iterators, lists, vectors

Niko Matsakis niko at alum.mit.edu
Thu Jan 12 10:18:17 PST 2012

On 1/12/12 9:47 AM, Graydon Hoare wrote:
> More generally though, I think block-centric is best, and perhaps 
> provide a standard vec method that appends-to-a-vec everything fed to it. 

+1.  I was beginning to work on a generic iter module that provided 
meta-programming features for blocks.  One of them would be to_list:

     type iterfn<T> = block(block(t: T));
     fn to_list<T>(iter: iterfn<T>) -> [T] {
         let result = [];
         iter {|i| result += [i]; }
         ret result;

I believe you could then use this like:

     let keys = to_list(bind hash.keys(_));

or with an appropriate interface/impl pair:

     let keys = bind hash.keys(_).to_list();

or even:

     let keys = hash.keys.to_list();

if we implemented the syntax that "hash.keys" where "keys" is a method.


More information about the Rust-dev mailing list