Sort #190
maxatome
started this conversation in
Suggestions for new operators
Sort
#190
Replies: 1 comment
-
Implemented in branch sort, doc & tests to be completed, examples to be done. |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
usage:
Sort
would be a smuggler operator allowing to sort a slice or an array before comparing its content.Accepted input: any slice or array.
Output: slice
If the input is
[]T
or[n]T
,HOW_TO_SORT
can be:1
or anyint
> 0: checks the slice/array is ordered in ascending order;-1
or anyint
< 0: checks the slice/array is ordered in descending order;func (a, b T) bool
returning true ifa < b
: checks the slice/array is ordered according to the function passed;[]string{"FIELD1", "FIELD2", …}
: only ifT
is a struct or a pointer on a struct, checks the slice/array of structs is ordered by struct fieldFIELD1
, then by fieldFIELD2
, …Fields can be prefixed by "-" to specify a descending order instead of ascending default one.
Unless for the
func (a, b T) bool
case, sorting would be handled the same way tdutil.SortableValues does.Examples of use:
Other examples of
HOW_TO_SORT
values can be found inSorted
discussion & examples.Note: the goal is not to replace
Bag
but to provide an alternative. In the case of slice of big structs, theBag
error report is sometimes hard to read while only one field mismatches.Beta Was this translation helpful? Give feedback.
All reactions