Thanks for reading this microblog and subscribe to my YT Channel The Data Singh for constant updates on Python, Interviews, Company Reviews. Iota is a useful concept for creating incrementing constants in Go. This article will cover several different ways in which you can use iota, and tips on where to be cautious with it's use. However, there are several areas where iota may not be appropriate to use. This will automatically assign unique values to all these constant variables.īy default, it starts the values from 0 and increments the values by 1 with every constant but this is not something we can rely on, so be careful while using Iota. Iota is a useful concept for creating incrementing constants in Go. These are just 7 unique values, if you were to create let's say 100 such values you don't have to assign unique values to these constants, you can use iota to get unique values for all these constants. The only thing these values should follow is that they have to be unique i.e Monday should not be equal to any other value. In this situation, values 1,2,3,4,5,6 don't make much sense. Let's say you want to define 7 constant Monday, Tuesday, Wednesday. In your second example youre ranging over the map and getting the key stored in k which only contains 1 and 2. The value being stored in k is the current index 0, 1, 2. It can be used to construct a set of related constants.īasically, Iota is a keyword in Go that helps you to give random values to your constant. 1 Answer Sorted by: 0 Youre expecting range to behave the same on both types but in the first case its ranging over an array and you just have an empty index 0. Its value is the index of the respective ConstSpec in that constant declaration, starting at zero. Within a constant declaration, the predeclared identifier iota represents successive untyped integer constants. Like many other languages Go support the concept of enums through the IOTA function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |