coinsort source pure
Package coinsort provides helpers to sort a slice of banker.Coins using the classic sort.Sort API (without relying on...
Package coinsort provides helpers to sort a slice of banker.Coins using the classic sort.Sort API (without relying on sort.Slice).
Usage examples:
Example
1coins := banker.GetCoins("g1....")
2
3// Ascending by balance
4coinsort.SortByBalance(coins)
5
6// Custom order – largest balance first
7coinsort.SortBy(coins, func(a, b chain.Coin) bool {
8 return a.Amount > b.Amount // descending
9})
Note: when getting banker.Coins from the banker, it's sorted by denom by default.
2
func SortByBalance
SortByBalance sorts c in ascending order by Amount.
Example
1coinsort.SortByBalance(myCoins)
2
2
- chain stdlib
- sort stdlib