github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/examples/sites/globalstate/gen_person_chooser_sortGen.go (about)

     1  // Code generated by sortGen. DO NOT EDIT.
     2  
     3  package main
     4  
     5  import "sort"
     6  import "myitcv.io/sorter"
     7  
     8  import "myitcv.io/react/examples/sites/globalstate/model"
     9  
    10  func sortPeopleKeysByName(vs *model.People) *model.People {
    11  	theVs := vs.AsMutable()
    12  
    13  	sort.Sort(&sorter.Wrapper{
    14  		LenFunc: func() int {
    15  			return theVs.Len()
    16  		},
    17  		LessFunc: func(i, j int) bool {
    18  			return bool(orderPeopleKeysByName(theVs, i, j))
    19  		},
    20  		SwapFunc: func(i, j int) {
    21  			jPrev := theVs.Get(j)
    22  			iPrev := theVs.Get(i)
    23  
    24  			theVs.Set(j, iPrev)
    25  			theVs.Set(i, jPrev)
    26  		},
    27  	})
    28  
    29  	return theVs.AsImmutable(vs)
    30  }
    31  func stableSortPeopleKeysByName(vs *model.People) *model.People {
    32  	theVs := vs.AsMutable()
    33  
    34  	sort.Stable(&sorter.Wrapper{
    35  		LenFunc: func() int {
    36  			return theVs.Len()
    37  		},
    38  		LessFunc: func(i, j int) bool {
    39  			return bool(orderPeopleKeysByName(theVs, i, j))
    40  		},
    41  		SwapFunc: func(i, j int) {
    42  			jPrev := theVs.Get(j)
    43  			iPrev := theVs.Get(i)
    44  
    45  			theVs.Set(j, iPrev)
    46  			theVs.Set(i, jPrev)
    47  		},
    48  	})
    49  
    50  	return theVs.AsImmutable(vs)
    51  }