Skip to content

Commit ccd7a75

Browse files
author
akshaydayma
authored
Rules for Composite Type
I added rules for composite type with description.
1 parent 303b7a5 commit ccd7a75

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

design/go2draft-type-parameters.md

+61
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,67 @@ composite type appears in a type list.
18561856
It does not apply when a composite type is formed from a type
18571857
parameter outside of a type list, as in `var v []T` for some type
18581858
parameter `T`.
1859+
##Arrays
1860+
Arrays can be reffered to as a __list__ of iteams of the same type.
1861+
Go's Arrays are fixed size,this means that during declaration,you must specify
1862+
the size of array and type it will contain,these cannot be change at runtime.
1863+
...GO
1864+
var children[2]string
1865+
children[0] = "Elves"
1866+
//or
1867+
children := [2]string{"Elves","Men"}
1868+
1869+
We can use 'len' to get the length of the array.For cases where we don't know
1870+
the number of elements we'll be dealing with upfront,we can turn to slices.
1871+
##Slices
1872+
Slices are lightweight structures that represent a portion of an array. You'll
1873+
most likely use slices way more than you'll be using Arrays in your programs.
1874+
...go 0 1
1875+
children :=[]string{"Elves","Men"}
1876+
//or
1877+
children := make([]string,2,5)
1878+
A slices can also be created from an existing array
1879+
...go 0 1 2 3 4 5 6
1880+
valar := [7]string{"Manwe","Ulmo","Aule","Yavanna","Varda","Este","Nienna"}
1881+
ladies := valar[2:]
1882+
...
1883+
##Maps
1884+
Maps are key - value pairs structure. In some language ,they are called Hashtables or
1885+
Dictionaries.
1886+
...go
1887+
clans:= make(map[string]string)
1888+
clans["Feanor"] = "Noldo Elves"
1889+
1890+
//or
1891+
clans := map[string]string{
1892+
"Feanor" : "Noldo",
1893+
}
1894+
//get the length
1895+
l := len(clans)
1896+
//Delete
1897+
delete(clans,"Noldo")
1898+
...
1899+
##Structs
1900+
A struct is a data type that aggregates different kinds of data values of different types. A
1901+
classic example of a struct would be the data representation of the COVID19 status in Nigeria.
1902+
...go
1903+
type COVID19Stats struct {
1904+
Country string
1905+
NumberOfCases int
1906+
Safety SafetyMeasures
1907+
}
1908+
type SafetyMeasures struct {
1909+
First string
1910+
Second string
1911+
Third string
1912+
}
1913+
...
1914+
Note : If you want output in JSON format thenthe first letter of field name(Country,NumberOfCases,Safety)
1915+
in struct should be uppercase.
1916+
1917+
1918+
1919+
18591920

18601921
```
18611922
// structField is a type constraint with a list of structs that all

0 commit comments

Comments
 (0)