types
This commit is contained in:
13
about_types.go
Normal file
13
about_types.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package go_koans
|
||||
|
||||
type coolNumber int
|
||||
|
||||
func (cn coolNumber) double() int {
|
||||
return int(cn) * 2
|
||||
}
|
||||
|
||||
func aboutTypes() {
|
||||
i := coolNumber(4)
|
||||
assert(i == coolNumber(__int__)) // values can be converted between compatible types
|
||||
assert(i.double() == __int__) // you can add methods on any type you define
|
||||
}
|
||||
@@ -22,6 +22,7 @@ func TestKoans(t *testing.T) {
|
||||
aboutStrings()
|
||||
aboutArrays()
|
||||
aboutSlices()
|
||||
aboutTypes()
|
||||
aboutControlFlow()
|
||||
aboutEnumeration()
|
||||
aboutAnonymousFunctions()
|
||||
|
||||
Reference in New Issue
Block a user