Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "github.com/fighterlyt/permutation"
- "reflect"
- )
- type Phone struct {
- ID int
- Vendor string
- }
- func main() {
- phone := []Phone{
- Phone{1, "Samsung"},
- Phone{2, "HTC"},
- Phone{3, "LG"},
- Phone{4, "Sony"},
- }
- perm, _ := permutation.NewPerm(phone, func(i, j interface{}) bool {
- return reflect.ValueOf(i).FieldByName("ID").Int() < reflect.ValueOf(j).FieldByName("ID").Int()
- })
- for elem, err := perm.Next(); err == nil; elem, err = perm.Next() {
- fmt.Println(elem, perm.Left())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement