Counters

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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

func NewUpCounter(upperLimit int) UpCounter

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

func (c UpCounter) Advance() (UpCounter, bool)

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

func (c UpCounter) CurrentCount() int

CurrentCount returns the current count of the UpCounter.

Returns:

  • int: The current count of the UpCounter.

func (UpCounter) Distance added in v0.4.9

func (c UpCounter) Distance() int

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) GoString added in v0.4.9

func (c UpCounter) GoString() string

GoString implements the fmt.GoStringer interface.

func (UpCounter) InitialCount added in v0.4.9

func (c UpCounter) InitialCount() int

InitialCount returns the upper limit of the UpCounter, which is the initial count.

Returns:

  • int: The upper limit of the UpCounter.

func (UpCounter) IsDone

func (c UpCounter) IsDone() bool

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) Reset added in v0.2.9

func (c UpCounter) Reset() UpCounter

Reset resets the UpCounter to its initial state.

func (UpCounter) Retreat added in v0.2.6

func (c UpCounter) Retreat() (UpCounter, bool)

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

func (c UpCounter) RetreatCount() int

RetreatCount returns the number of times the UpCounter has been retreated.

Returns:

  • int: The number of times the counter has been retreated.

Jump to

Keyboard shortcuts

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