Copyright 2017, The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE.md file.
package cmpopts
import (
)
SortSlices returns a Transformer option that sorts all []V. The less function must be of the form "func(T, T) bool" which is used to sort any slice with element type V that is assignable to T. The less function must be: • Deterministic: less(x, y) == less(x, y) • Irreflexive: !less(x, x) • Transitive: if !less(x, y) and !less(y, z), then !less(x, z) The less function does not have to be "total". That is, if !less(x, y) and !less(y, x) for two elements x and y, their relative order is maintained. SortSlices can be used in conjunction with EquateEmpty.
SortMaps returns a Transformer option that flattens map[K]V types to be a sorted []struct{K, V}. The less function must be of the form "func(T, T) bool" which is used to sort any map with key K that is assignable to T. Flattening the map into a slice has the property that cmp.Equal is able to use Comparers on K or the K.Equal method if it exists. The less function must be: • Deterministic: less(x, y) == less(x, y) • Irreflexive: !less(x, x) • Transitive: if !less(x, y) and !less(y, z), then !less(x, z) • Total: if x != y, then either less(x, y) or less(y, x) SortMaps can be used in conjunction with EquateEmpty.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.