This file contains hidden or 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
| str, ok := value.(string) | |
| if ok { | |
| fmt.Printf("string value is: %q\n", str) | |
| } else { | |
| fmt.Printf("value is not a string\n") | |
| } |
This file contains hidden or 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
| type Sequence []int | |
| // Method for printing - sorts the elements before printing | |
| func (s Sequence) String() string { | |
| sort.IntSlice(s).Sort() | |
| return fmt.Sprint([]int(s)) | |
| } |
This file contains hidden or 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
| type Sequence []int | |
| // Methods required by sort.Interface. | |
| func (s Sequence) Len() int { | |
| return len(s) | |
| } | |
| func (s Sequence) Less(i, j int) bool { | |
| return s[i] < s[j] | |
| } | |
| func (s Sequence) Swap(i, j int) { |
This file contains hidden or 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
| type ByteSlice []byte | |
| func (p *ByteSlice) Write(data []byte) (n int, err error) { | |
| slice := *p | |
| // Again as above. | |
| *p = slice | |
| return len(data), nil | |
| } | |
| var b ByteSlice | |
| fmt.Fprintf(&b, "This hour has %d days\n", 7) |
This file contains hidden or 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
| []rune(input) |
This file contains hidden or 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
| var builtinActions = map[operationType]*action{ | |
| asdasdd | |
| } |
This file contains hidden or 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
| defer func() { | |
| if r := recover(); r != nil { | |
| t.reportErrorAndStop() | |
| } | |
| }() |
This file contains hidden or 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
| package main | |
| import "fmt" | |
| func main() { | |
| var s []int | |
| fmt.Println(s, len(s), cap(s)) | |
| if s == nil { | |
| fmt.Println("nil!") | |
| } |
This file contains hidden or 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
| slice := make([]int, 10, 15) | |
| fmt.Printf("len: %d, cap: %d\n", len(slice), cap(slice)) | |
| newSlice := make([]int, len(slice), 2*cap(slice)) | |
| for i := range slice { | |
| newSlice[i] = slice[i] | |
| } | |
| slice = newSlice | |
| func Extend(slice []int, element int) []int { | |
| n := len(slice) |
This file contains hidden or 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
| type path []byte | |
| func (p path) ToUpper() { | |
| for i, b := range p { | |
| if 'a' <= b && b <= 'z' { | |
| p[i] = b + 'A' - 'a' | |
| } | |
| } | |
| } |