On Friday, June 30, 2017 at 9:28:50 PM UTC-6, Manohar Reddy wrote:
>
> `iota` is golnag's enum. I've seen this code in Wikipedia. But I did not 
> understand it. Can someone please explain this code?
>

In the first line of the const block, iota is 0, and this is assigned to "_" 
(i.e., discarded).

In the second line of the const block, iota is 1, so KB (of type ByteSize) 
is defined as 1 << (10 * 1), which is 1024.

The third line of the const block inherits the previous line's pattern so 
it's effectively KB ByteSize = 1 << (10 * iota). Because iota is now 2, MB 
is defined as 1 << (10 * 2), which is 1048576.

Likewise, in the fourth line of the const block, iota is 3 so GB is defined 
as 1 << (10 * 3), which is 1073741824.

— Scott

-- 
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