github.com/mattn/anko@v0.1.10/packages/sort.go (about)

     1  package packages
     2  
     3  import (
     4  	"reflect"
     5  	"sort"
     6  
     7  	"github.com/mattn/anko/env"
     8  )
     9  
    10  // SortFuncsStruct provides functions to be used with Sort
    11  type SortFuncsStruct struct {
    12  	LenFunc  func() int
    13  	LessFunc func(i, j int) bool
    14  	SwapFunc func(i, j int)
    15  }
    16  
    17  func (s SortFuncsStruct) Len() int           { return s.LenFunc() }
    18  func (s SortFuncsStruct) Less(i, j int) bool { return s.LessFunc(i, j) }
    19  func (s SortFuncsStruct) Swap(i, j int)      { s.SwapFunc(i, j) }
    20  
    21  func init() {
    22  	env.Packages["sort"] = map[string]reflect.Value{
    23  		"Float64s":          reflect.ValueOf(sort.Float64s),
    24  		"Float64sAreSorted": reflect.ValueOf(sort.Float64sAreSorted),
    25  		"Ints":              reflect.ValueOf(sort.Ints),
    26  		"IntsAreSorted":     reflect.ValueOf(sort.IntsAreSorted),
    27  		"IsSorted":          reflect.ValueOf(sort.IsSorted),
    28  		"Search":            reflect.ValueOf(sort.Search),
    29  		"SearchFloat64s":    reflect.ValueOf(sort.SearchFloat64s),
    30  		"SearchInts":        reflect.ValueOf(sort.SearchInts),
    31  		"SearchStrings":     reflect.ValueOf(sort.SearchStrings),
    32  		"Sort":              reflect.ValueOf(sort.Sort),
    33  		"Stable":            reflect.ValueOf(sort.Stable),
    34  		"Strings":           reflect.ValueOf(sort.Strings),
    35  		"StringsAreSorted":  reflect.ValueOf(sort.StringsAreSorted),
    36  	}
    37  	env.PackageTypes["sort"] = map[string]reflect.Type{
    38  		"Float64Slice":    reflect.TypeOf(sort.Float64Slice{}),
    39  		"IntSlice":        reflect.TypeOf(sort.IntSlice{}),
    40  		"StringSlice":     reflect.TypeOf(sort.StringSlice{}),
    41  		"SortFuncsStruct": reflect.TypeOf(&SortFuncsStruct{}),
    42  	}
    43  	sortGo18()
    44  }