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
package main | |
import ( | |
"fmt" | |
"sort" | |
) | |
func main() { | |
var script map[int]string |
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
package main | |
import "fmt" | |
func main() { | |
basket(map[string]string{ | |
"name": "apple", | |
"flavour": "It's a little sour and bitter, but mostly sweet, not at all salty, very juicy in general.", | |
}, "fruit") | |
} |
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
package main | |
import "fmt" | |
func main() { | |
produce := map[string][]string{ | |
"fruits": []string{"Apple", "Mango", "Orange", "Banana"}, | |
"veggies": []string{"Cucumber", "Carrot", "Kale", "Broccoli"}, | |
} | |
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
package main | |
import "fmt" | |
type produce struct { | |
name string | |
flavour string | |
kind string | |
} |
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
package main | |
import "fmt" | |
type basket []map[string]string | |
func main() { | |
basket := new(basket) | |
basket.add_item(map[string]string{ |
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
class Basket | |
def initialize | |
@basket = [] | |
end | |
def add_item(kind, **item) | |
@basket << item.merge({kind: kind}) | |
puts "Entry #{item[:name]} created!" | |
puts | |
end |
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
package main | |
import "fmt" | |
func basket(fruits ...string) { | |
for _, fruit := range fruits { | |
fmt.Printf("%s is in the basket\n", fruit) | |
} | |
} |
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
func (receiverName receiverType) functionName(parameterName parameterType) { | |
// we can set the value of an _already initialised_ receiver type | |
// but we cannot modify the receiver type directly | |
receiverName = parameterName | |
// we can access the value of the _already initialised_ receiver type (getters) | |
fmt.Println(receiverName) | |
} |
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
func (receiverName *receiverType) functionName(parameterName parameterType) { | |
// we can directly set the value of the receiver type (setter) | |
*receiverName = parameterName | |
// we can also access the value of the receiver type (getter) | |
fmt.Println(receiverName) | |
} |
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
package main | |
import "fmt" | |
type basket []produce | |
type produce struct { | |
name string | |
flavour string | |
kind string | |
} |