iterator and tuple with forIterator

View: New views
1 Messages — Rating Filter:   Alert me  

iterator and tuple with forIterator

by Dan Shryock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

As an experiment to become more familiar with nice, I decided to try
to build a new forIterator method for maps that allows you to iterate
over a tuple of key values.  The forIterator looks like the following,
and works fine:

<K,V> Iterator<(K,V)> forIterator(Map<K,V> map){
        let entries = map.entrySet().iterator();
        return (() => {
                if(entries.hasNext()){
                        let entry = entries.next();
                        return (entry.getKey(),entry.getValue());
                }
                return stop();
        }).iterator();
}

However to use the forIterator, I had to place a temporary variable as
the item in the for statement, then pull the values out inside the
loop.
void main(String[] args){

        Map<String,String> mapdata = listToMap([
                                        ("test1","Bla1"),
                                        ("test2","Bla2")
                                        ]);

        //This works
        for(entry :mapdata){
                (String key, String value) = entry;
                println("Map Iteration Test:" key "=" value);
        }

        //Doesn't compile
        for((String key, String value):mapdata)
                println("Map Iteration Test:" key "=" value);

}

Is this a bug, or is there another way to express this without the
temp variable?

Thanks

Dan

BTW: I haven't been able to get buy in to start using nice, but it is
indeed a very nice language to play with

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Nice-info mailing list
Nice-info@...
https://lists.sourceforge.net/lists/listinfo/nice-info
LightInTheBox - Buy quality products at wholesale price