range on slices seem similar. The loop has the current index so looking 
ahead, behind, or reslicing is convenient.

>From https://golang.org/ref/spec#For_statements:

For an array, pointer to array, or slice value a, the index iteration 
> values are produced in increasing order, starting at element index 0. If at 
> most one iteration variable is present, the range loop produces iteration 
> values from 0 up to len(a)-1 and does not index into the array or slice 
> itself. For a nil slice, the number of iterations is 0.


Modifying the slice in-place doesn't change the iteration because of "does 
not index into the array or slice 
itself": https://play.golang.org/p/bXT4fwnDCC6

So to get prepend+next behavior you may need to try something else.

Matt

On Saturday, January 20, 2018 at 1:51:54 PM UTC-6, Peng Yu wrote:
>
> Hi, the concept of peekable iterator from python is very convenient. 
> Is there something similar in golang. 
>
>
> https://github.com/erikrose/more-itertools/blob/master/more_itertools/more.py#L134
>  
>
> -- 
> Regards, 
> Peng 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to