Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 673 Bytes

README.md

File metadata and controls

32 lines (21 loc) · 673 Bytes

Keysort - go module to sort slices by key

This module introduce function keysort.Sort that enables sort slice by key, like it's done in python sorted function.

Usage

package main

import (
	"fmt"

	"github.com/itroot/keysort"
)

func main() {
	slice := []int{1, 2, 3, 4, 5}
	keysort.Sort(slice, func(i int) keysort.Sortable {
		return keysort.Sequence{slice[i]%2 == 1, slice[i]}
	})
	fmt.Println(slice)
}

will output [2 4 1 3 5], first all even numbers in sorted order, and then all odd numbers in sorted order

Other examples