Limit class sealed

A value object representing an upper bound (limit) typically used in pagination, query constraints, or result-size restrictions.

A Limit expresses either:

  • a finite limit: created via Limit.of, representing a concrete non-negative maximum, or
  • an unbounded state: created via Limit.unlimited, representing no restriction.

This abstraction helps unify pagination and bounded queries while maintaining immutability and type safety.

Creation Examples

final limited = Limit.of(10);     // Max 10 items
final unlimited = Limit.unlimited(); // No maximum

print(limited.isLimited()); // true
print(unlimited.isUnlimited()); // true

Design Notes

  • Negative values are not allowed; enforcing correctness at construction.
  • Subtypes must implement max and isLimited.
  • Use isUnlimited to check for unbounded conditions instead of manually comparing values.

Example Behavior

Input Result Type isLimited max()
Limit.of(5) _Limited true 5
Limit.unlimited() _Unlimited false n/a

See Also

  • Limiting
  • pagination utilities or query builders that depend on limits.
Inheritance
Implemented types

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

equalizedProperties() → List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
isLimited() → bool
Returns true if this limit represents a concrete, non-negative maximum.
isUnlimited() → bool
Returns true if this limit has no upper bound.
max() → int
Returns the concrete maximum number of elements allowed by this limit.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

of(int max) → Limit
Creates a finite limit with the given max value.
unlimited() → Limit
Creates an unlimited (unbounded) limit.