currency

package
v0.210929.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2021 License: CC0-1.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MaxAmount = Amount(math.MaxUint32)

Variables

View Source
var (
	ErrNominalInvalid = errors.New("Nominal is not valid for this group")
	ErrNominalCount   = errors.New("Not enough nominals for this amount")
)

Functions

This section is empty.

Types

type Amount

type Amount uint32

Amount is integer counting lowest currency unit, e.g. $1.20 = 120

func (Amount) Format100I

func (self Amount) Format100I() string

func (Amount) FormatCtx

func (self Amount) FormatCtx(ctx context.Context) string

type ExpendCombine

type ExpendCombine struct {
	S1    ExpendStrategy
	S2    ExpendStrategy
	Ratio float32
	// contains filtered or unexported fields
}

func (*ExpendCombine) ExpendOne

func (self *ExpendCombine) ExpendOne(from *NominalGroup, max Amount) (Nominal, error)

func (*ExpendCombine) Reset

func (self *ExpendCombine) Reset(from *NominalGroup)

func (*ExpendCombine) Validate

func (self *ExpendCombine) Validate() bool

type ExpendGenericOrder

type ExpendGenericOrder struct {
	SortElemFunc ngOrderSortElemFunc
	// contains filtered or unexported fields
}

func (*ExpendGenericOrder) ExpendOne

func (self *ExpendGenericOrder) ExpendOne(from *NominalGroup, max Amount) (Nominal, error)

func (*ExpendGenericOrder) Reset

func (self *ExpendGenericOrder) Reset(from *NominalGroup)

func (*ExpendGenericOrder) Validate

func (self *ExpendGenericOrder) Validate() bool

type ExpendStatistical

type ExpendStatistical struct {
	Stat *NominalGroup
	// contains filtered or unexported fields
}

func (*ExpendStatistical) ExpendOne

func (self *ExpendStatistical) ExpendOne(from *NominalGroup, max Amount) (Nominal, error)

func (*ExpendStatistical) Reset

func (self *ExpendStatistical) Reset(from *NominalGroup)

func (*ExpendStatistical) Validate

func (self *ExpendStatistical) Validate() bool

type ExpendStrategy

type ExpendStrategy interface {
	Reset(from *NominalGroup)
	ExpendOne(from *NominalGroup, max Amount) (Nominal, error)
	Validate() bool
}

NominalGroup.Withdraw = strategy.Reset + loop strategy.ExpendOne

func NewExpendLeastCount

func NewExpendLeastCount() ExpendStrategy

func NewExpendMostAvailable

func NewExpendMostAvailable() ExpendStrategy

type Nominal

type Nominal Amount

Nominal is value of one coin or bill

type NominalGroup

type NominalGroup struct {
	// contains filtered or unexported fields
}

NominalGroup operates money comprised of multiple nominals, like coins or bills. coin1 : 3 coin5 : 1 coin10: 4 total : 48

func (*NominalGroup) Add

func (self *NominalGroup) Add(n Nominal, count uint) error

func (*NominalGroup) AddFrom

func (self *NominalGroup) AddFrom(source *NominalGroup)

func (*NominalGroup) Clear

func (self *NominalGroup) Clear()

func (*NominalGroup) Copy

func (self *NominalGroup) Copy() *NominalGroup

func (*NominalGroup) Diff

func (self *NominalGroup) Diff(other *NominalGroup) Amount

func (*NominalGroup) Get

func (self *NominalGroup) Get(n Nominal) (uint, error)

func (*NominalGroup) Iter

func (self *NominalGroup) Iter(f func(nominal Nominal, count uint) error) error

func (*NominalGroup) MustAdd

func (self *NominalGroup) MustAdd(n Nominal, count uint)

MustAdd just adds count ignoring valid nominals.

func (*NominalGroup) SetValid

func (self *NominalGroup) SetValid(valid []Nominal)

func (*NominalGroup) String

func (self *NominalGroup) String() string

func (*NominalGroup) Sub

func (self *NominalGroup) Sub(other *NominalGroup)

func (*NominalGroup) ToMapUint32

func (self *NominalGroup) ToMapUint32(m map[uint32]uint32)

func (*NominalGroup) Total

func (self *NominalGroup) Total() Amount

func (*NominalGroup) Withdraw

func (self *NominalGroup) Withdraw(to *NominalGroup, a Amount, strategy ExpendStrategy) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL