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
-module(mylist). | |
-export([flatten/1]). | |
flatten(L) -> flatten(L, []). | |
flatten([], Acc) -> Acc; | |
flatten([H|T], Acc) when is_list(H) -> flatten(T, Acc ++ flatten(H)); | |
flatten([H|T], Acc) -> flatten(T, Acc ++ [H]). |
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 IO interface { | |
Read() string | |
Write(string) | |
} |
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
func main() { | |
acc := Account{Name: "Weerasak", Balance : 1000.00 } | |
acc.Deposit(500.00) | |
fmt.Println(acc) | |
} | |
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
func (acc *Account) Deposit(amount float64) { | |
acc.Balance += amount | |
} |
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
func main() { | |
acc := Account{Name: "Weerasak", Balance : 1000.00 } | |
fmt.Println(acc.String()) | |
pacc := &acc | |
fmt.Println(pacc.String()) | |
} |
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
func (acc Account) String() string { | |
return fmt.Sprintf("Account %s have balance %0.2f", acc.Name, acc.Balance) | |
} |
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 Account struct { | |
Name string | |
Balance float64 | |
} |
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 space(ch rune, end rune) (side int, in int) { | |
if ch == 'A' { | |
in = 0 | |
} else { | |
in = int((ch-'A')*2 - 1) | |
} |
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
func ExampleJsonFormat() { | |
r := bytes.NewReader([]byte(`{"name":"Weerasak"}`)) | |
formated, _ := From(r) | |
fmt.Println(formated) | |
// Output: | |
// { | |
// "name": "Weerasak" | |
// } | |
} |
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 ( | |
"log" | |
"gopkg.in/mgo.v2" | |
"gopkg.in/mgo.v2/bson" | |
) | |
func main() { |