Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

coinsort source pure

Package coinsort provides helpers to sort a slice of banker.Coins using the classic sort.Sort API (without relying on...

Overview

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.

Functions 2

func SortBy

1func SortBy(c chain.Coins, less LessFunc)
source

SortBy sorts c in place using the provided LessFunc.

Example – descending by Amount:

Example
1coinsort.SortBy(coins, func(a, b banker.Coin) bool {
2    return a.Amount > b.Amount
3})

func SortByBalance

1func SortByBalance(c chain.Coins)
source

SortByBalance sorts c in ascending order by Amount.

Example
1coinsort.SortByBalance(myCoins)

Types 2

type ByAmount

struct
1type ByAmount struct{ chain.Coins }
source

Methods on ByAmount

func Len

method on ByAmount
1func (b ByAmount) Len() int
source

func Less

method on ByAmount
1func (b ByAmount) Less(i, j int) bool
source

func Swap

method on ByAmount
1func (b ByAmount) Swap(i, j int)
source

Imports 2

  • chain stdlib
  • sort stdlib

Source Files 3