Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AmountAllocation ¶
type AmountAllocation[T any] struct { Key T Amount alpacadecimal.Decimal }
AmountAllocation is the allocated currency amount for one key.
func AllocateByAmount ¶
func AllocateByAmount[T any](calculator Calculator, input AmountAllocationInput[T]) ([]AmountAllocation[T], error)
AllocateByAmount allocates a currency amount across currency amount buckets using the largest remainder quota method. Each item amount is both its proportional weight and its allocation cap.
type AmountAllocationInput ¶
type AmountAllocationInput[T any] struct { Amount alpacadecimal.Decimal Items []AmountAllocationItem[T] // CompareKey is used as a deterministic tie-breaker when two buckets have // the same fractional remainder. If nil, the original item order is used. CompareKey func(left, right T) int }
AmountAllocationInput defines a proportional allocation across currency amount buckets.
type AmountAllocationItem ¶
type AmountAllocationItem[T any] struct { Key T Amount alpacadecimal.Decimal }
AmountAllocationItem defines one currency amount bucket that can receive a proportional allocation. The amount is both the allocation weight and the maximum amount that can be allocated to the key.
type Calculator ¶
TODO: Better name?!
func (Calculator) IsRoundedToPrecision ¶
func (c Calculator) IsRoundedToPrecision(amount alpacadecimal.Decimal) bool
func (Calculator) RoundToPrecision ¶
func (c Calculator) RoundToPrecision(amount alpacadecimal.Decimal) alpacadecimal.Decimal
func (Calculator) Validate ¶
func (c Calculator) Validate() error
type Code ¶
Currency represents a currency code. Three-letter [ISO4217](https://www.iso.org/iso-4217-currency-codes.html) currency code.
func (Code) Calculator ¶
func (c Code) Calculator() (Calculator, error)
Calculator provides a currency calculator object. This allows us to not to resolve def a lot of times, plus we can assume that def is always valid, thus we can avoid a lot of error handling.
type WeightedAllocation ¶
type WeightedAllocation[T any] struct { Key T Amount alpacadecimal.Decimal }
WeightedAllocation is the allocated currency amount for one key.
func AllocateByWeight ¶
func AllocateByWeight[T any](calculator Calculator, input WeightedAllocationInput[T]) ([]WeightedAllocation[T], error)
AllocateByWeight allocates a currency amount across keys using their weights and the largest remainder quota method at the currency precision.
type WeightedAllocationInput ¶
type WeightedAllocationInput[T any] struct { Amount alpacadecimal.Decimal Items []WeightedAllocationItem[T] // CompareKey is used as a deterministic tie-breaker when two items have // the same fractional remainder. If nil, the original item order is used. CompareKey func(left, right T) int }
WeightedAllocationInput defines a proportional currency allocation.
type WeightedAllocationItem ¶
type WeightedAllocationItem[T any] struct { Key T Weight alpacadecimal.Decimal }
WeightedAllocationItem defines one key that can receive a proportional allocation from a currency amount. Weight is dimensionless; it does not need to be a currency amount.