github.com/alexandrestein/gods@v1.0.1/containers/containers.go (about)

     1  // Copyright (c) 2015, Emir Pasic. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package containers provides core interfaces and functions for data structures.
     6  //
     7  // Container is the base interface for all data structures to implement.
     8  //
     9  // Iterators provide stateful iterators.
    10  //
    11  // Enumerable provides Ruby inspired (each, select, map, find, any?, etc.) container functions.
    12  //
    13  // Serialization provides serializers (marshalers) and deserializers (unmarshalers).
    14  package containers
    15  
    16  import "github.com/alexandrestein/gods/utils"
    17  
    18  // Container is base interface that all data structures implement.
    19  type Container interface {
    20  	Empty() bool
    21  	Size() int
    22  	Clear()
    23  	Values() []interface{}
    24  }
    25  
    26  // GetSortedValues returns sorted container's elements with respect to the passed comparator.
    27  // Does not effect the ordering of elements within the container.
    28  func GetSortedValues(container Container, comparator utils.Comparator) []interface{} {
    29  	values := container.Values()
    30  	if len(values) < 2 {
    31  		return values
    32  	}
    33  	utils.Sort(values, comparator)
    34  	return values
    35  }