Skip to content

Commit

Permalink
Custom type declaration with Go Approach
Browse files Browse the repository at this point in the history
  • Loading branch information
gandhi-jay committed Dec 1, 2017
1 parent 3caf611 commit 776f617
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions go_stephen_grider/code/03_cards_deck/deck.go
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)
}
}
17 changes: 17 additions & 0 deletions go_stephen_grider/code/03_cards_deck/main.go
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"
}

0 comments on commit 776f617

Please sign in to comment.