Copyright | © 2018-2024 Intersect MBO |
---|---|
License | Apache-2.0 |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module contains an implementation of the Largest-First coin selection algorithm.
Synopsis
- largestFirst :: (Ord i, Monad m) => CoinSelectionAlgorithm i o m
Documentation
largestFirst :: (Ord i, Monad m) => CoinSelectionAlgorithm i o m Source #
An implementation of the Largest-First coin selection algorithm.
The Largest-First coin selection algorithm considers available inputs in descending order of value, from largest to smallest.
When applied to a set of requested outputs, the algorithm repeatedly selects entries from the available inputs set until the total value of selected entries is greater than or equal to the total value of requested outputs.
Change Values
If the total value of selected inputs is greater than the total value of
all requested outputs, the change
set of the resulting selection will
contain a single coin with the excess value.
If the total value of selected inputs is exactly equal to the total value
of all requested outputs, the change
set of the resulting selection will
be empty.
Failure Modes
The algorithm terminates with an error if:
The total value of
inputsAvailable
(the amount of money available) is less than the total value ofoutputsRequested
(the amount of money required).It is not possible to cover the total value of
outputsRequested
without selecting a number of inputs frominputsAvailable
that would exceed the maximum defined bylimit
.See:
InputLimitExceededError
.
Since: 1.0.0