currency

package
v0.230719.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: CC0-1.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MaxAmount = Amount(math.MaxUint32)

Variables

View Source
var (
	ErrNominalInvalid = oerr.New("Nominal is not valid for this group")
	ErrNominalCount   = oerr.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) AddPersent added in v0.220223.0

func (a Amount) AddPersent(persent float64) Amount

func (Amount) Format100I

func (a Amount) Format100I() string

func (Amount) FormatCtx

func (a 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 (ec *ExpendCombine) ExpendOne(from *NominalGroup, max Amount) (Nominal, error)

func (*ExpendCombine) Reset

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

func (*ExpendCombine) Validate

func (ec *ExpendCombine) Validate() bool

type ExpendGenericOrder

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

func (*ExpendGenericOrder) ExpendOne

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

func (*ExpendGenericOrder) Reset

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

func (*ExpendGenericOrder) Validate

func (ego *ExpendGenericOrder) Validate() bool

type ExpendStatistical

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

func (*ExpendStatistical) ExpendOne

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

func (*ExpendStatistical) Reset

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

func (*ExpendStatistical) Validate

func (es *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

func (Nominal) Format100I added in v0.230424.2

func (n Nominal) Format100I() string

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 (ng *NominalGroup) Add(n Nominal) error

func (*NominalGroup) AddFrom

func (ng *NominalGroup) AddFrom(source *NominalGroup)

func (*NominalGroup) AddMany added in v0.230424.2

func (ng *NominalGroup) AddMany(n Nominal, count uint) error

func (*NominalGroup) Clear

func (ng *NominalGroup) Clear()

func (*NominalGroup) Copy

func (ng *NominalGroup) Copy() *NominalGroup

func (*NominalGroup) Diff

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

func (*NominalGroup) Get

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

func (*NominalGroup) InTube added in v0.230424.2

func (ng *NominalGroup) InTube(n Nominal) uint

func (*NominalGroup) Iter

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

func (*NominalGroup) MustAdd

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

MustAdd just adds count ignoring valid nominals.

func (*NominalGroup) SetValid

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

func (*NominalGroup) String

func (ng *NominalGroup) String() string

func (*NominalGroup) Sub

func (ng *NominalGroup) Sub(n Nominal) error

func (*NominalGroup) SubOther added in v0.230424.2

func (ng *NominalGroup) SubOther(other *NominalGroup)

func (*NominalGroup) ToMapUint32

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

func (*NominalGroup) Total

func (ng *NominalGroup) Total() Amount

func (*NominalGroup) Withdraw

func (ng *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