Documentation ¶
Index ¶
- type DownCounter
- func (c DownCounter) Advance() (DownCounter, bool)
- func (c DownCounter) CurrentCount() int
- func (c DownCounter) Distance() int
- func (c DownCounter) GoString() string
- func (c DownCounter) InitialCount() int
- func (c DownCounter) IsDone() bool
- func (c DownCounter) Reset() DownCounter
- func (c DownCounter) Retreat() (DownCounter, bool)
- func (c DownCounter) RetreatCount() int
- type UpCounter
- func (c UpCounter) Advance() (UpCounter, bool)
- func (c UpCounter) CurrentCount() int
- func (c UpCounter) Distance() int
- func (c UpCounter) GoString() string
- func (c UpCounter) InitialCount() int
- func (c UpCounter) IsDone() bool
- func (c UpCounter) Reset() UpCounter
- func (c UpCounter) Retreat() (UpCounter, bool)
- func (c UpCounter) RetreatCount() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DownCounter ¶ added in v0.2.6
type DownCounter struct {
// contains filtered or unexported fields
}
DownCounter represents a counter that decrements downwards until it reaches zero.
func NewDownCounter ¶ added in v0.2.6
func NewDownCounter(startingCount int) DownCounter
NewDownCounter creates a new DownCounter with the specified starting count.
Parameters:
- startingCount: The initial value of the counter.
Returns:
- DownCounter: A new DownCounter with the specified starting count.
If the startingCount is less than 0, it is set to 0.
func (DownCounter) Advance ¶ added in v0.2.6
func (c DownCounter) Advance() (DownCounter, bool)
Advance decrements the current count of the DownCounter by one.
Returns:
- DownCounter: A new DownCounter with the decremented current count.
- bool: true if the counter has not reached zero, false otherwise.
func (DownCounter) CurrentCount ¶ added in v0.4.9
func (c DownCounter) CurrentCount() int
CurrentCount returns the current count of the DownCounter.
Returns:
- int: The current count of the DownCounter.
func (DownCounter) Distance ¶ added in v0.4.9
func (c DownCounter) Distance() int
Distance returns the current count of the DownCounter. This is equivalent to the distance from zero, as the DownCounter decrements towards zero.
Returns:
- int: The current count of the DownCounter.
func (DownCounter) GoString ¶ added in v0.4.9
func (c DownCounter) GoString() string
GoString implements the fmt.GoStringer interface.
func (DownCounter) InitialCount ¶ added in v0.4.9
func (c DownCounter) InitialCount() int
InitialCount returns the starting count of the DownCounter, which is the initial count.
Returns:
- int: The starting count of the DownCounter.
func (DownCounter) IsDone ¶ added in v0.2.6
func (c DownCounter) IsDone() bool
IsDone checks if the DownCounter has reached zero.
Returns:
- bool: true if the counter has reached zero, false otherwise.
func (DownCounter) Reset ¶ added in v0.2.9
func (c DownCounter) Reset() DownCounter
Reset resets the DownCounter to its initial state.
func (DownCounter) Retreat ¶ added in v0.2.6
func (c DownCounter) Retreat() (DownCounter, bool)
Retreat increments the retrat count of the DownCounter by one and, as a result, decrements the current count by one.
Returns:
- DownCounter: A new DownCounter with the decremented current count.
- bool: true if the counter has not reached zero, false otherwise.
func (DownCounter) RetreatCount ¶ added in v0.4.9
func (c DownCounter) RetreatCount() int
RetreatCount returns the number of times the DownCounter has been retreated.
Returns:
- int: The number of times the DownCounter has been retreated.
type UpCounter ¶
type UpCounter struct {
// contains filtered or unexported fields
}
UpCounter represents a counter that increments upwards until it reaches an upper limit.
func NewUpCounter ¶
NewUpCounter creates a new UpCounter with the specified upper limit.
Parameters:
- upperLimit: The maximum limit that the counter can reach.
Returns:
- UpCounter: A new UpCounter with the specified upper limit.
If the upperLimit is less than 0, it is set to 0.
func (UpCounter) Advance ¶ added in v0.2.6
Advance increments the current count of the UpCounter by one.
Returns:
- UpCounter: A new UpCounter with the incremented current count.
- bool: true if the counter has not reached its upper limit, false otherwise.
func (UpCounter) CurrentCount ¶ added in v0.4.9
CurrentCount returns the current count of the UpCounter.
Returns:
- int: The current count of the UpCounter.
func (UpCounter) Distance ¶ added in v0.4.9
Distance calculates the distance between the current count and the upper limit of the UpCounter, that is, the number of times the counter can still be advanced before reaching the upper limit.
Returns:
- int: The distance between the current count and the upper limit.
func (UpCounter) InitialCount ¶ added in v0.4.9
InitialCount returns the upper limit of the UpCounter, which is the initial count.
Returns:
- int: The upper limit of the UpCounter.
func (UpCounter) IsDone ¶
IsDone checks if the UpCounter has reached its upper limit.
Returns:
- bool: true if the counter has reached its upper limit, false otherwise.
func (UpCounter) Retreat ¶ added in v0.2.6
Retreat increments the retreat count and, as a result, decrements the upper limit of the UpCounter by one.
Returns:
- UpCounter: A new UpCounter with the decremented upper limit.
- bool: true if the counter has not reached its upper limit, false otherwise.
func (UpCounter) RetreatCount ¶ added in v0.4.9
RetreatCount returns the number of times the UpCounter has been retreated.
Returns:
- int: The number of times the counter has been retreated.