-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom type declaration with Go Approach
- Loading branch information
1 parent
3caf611
commit 776f617
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Create a new type of deck | ||
// which is a slice of string. | ||
type deck []string | ||
|
||
func (d deck) print() { | ||
for i, card := range d { | ||
fmt.Println(i, card) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
cards := deck{newCard(), "Seven of Spades"} | ||
|
||
fmt.Println(cards) | ||
|
||
cards.print() | ||
} | ||
|
||
func newCard() string { | ||
return "Ace of Spades" | ||
} |