java.lang.Object
java.lang.Record
com.darkcollective.relix.function.Arity
Record Components:
min - the smallest number of arguments accepted; zero or more
max - the largest number accepted, or UNBOUNDED for no limit; when bounded, never smaller than min

public record Arity(int min, int max) extends Record
How many arguments a function accepts — an inclusive range, with UNBOUNDED standing for "no upper limit".

Arity is declared once, on the signature, and checked once, by the engine, before a function is invoked. An implementation therefore never has to count its own arguments: by the time it runs, the list it is handed is a length the declaration allows.

A range is what lets one definition serve what would otherwise be several. Round(x) and Round(x, places) are one function of arity between(1, 2), not two functions that differ only in how many arguments they take, and Coalesce is atLeast(1) rather than a fixed pair.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The value max() takes when a function accepts any number of arguments.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Arity(int min, int max)
    Creates an instance of a Arity record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    accepts(int count)
     
    static Arity
    atLeast(int min)
    At least min arguments, with no upper limit.
    static Arity
    between(int min, int max)
    Between min and max arguments, inclusive.
    Renders the range the way an error message wants it — "2", "1 to 3", "at least 1".
    final boolean
    Indicates whether some other object is "equal to" this one.
    static Arity
    exactly(int count)
    Exactly count arguments — the common case.
    final int
    Returns a hash code value for this object.
    boolean
     
    int
    max()
    Returns the value of the max record component.
    int
    min()
    Returns the value of the min record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNBOUNDED

      public static final int UNBOUNDED
      The value max() takes when a function accepts any number of arguments.
      See Also:
  • Constructor Details

    • Arity

      public Arity(int min, int max)
      Creates an instance of a Arity record class.
      Parameters:
      min - the value for the min record component
      max - the value for the max record component
  • Method Details

    • exactly

      public static Arity exactly(int count)
      Exactly count arguments — the common case.
      Parameters:
      count - the required number of arguments
      Returns:
      the fixed arity
    • between

      public static Arity between(int min, int max)
      Between min and max arguments, inclusive.
      Parameters:
      min - the smallest number accepted
      max - the largest number accepted
      Returns:
      the bounded range
    • atLeast

      public static Arity atLeast(int min)
      At least min arguments, with no upper limit.
      Parameters:
      min - the smallest number accepted
      Returns:
      the open-ended range
    • isUnbounded

      public boolean isUnbounded()
      Returns:
      true when there is no upper limit on the argument count
    • accepts

      public boolean accepts(int count)
      Parameters:
      count - a candidate number of arguments
      Returns:
      true when a call with count arguments is within range
    • describe

      public String describe()
      Renders the range the way an error message wants it — "2", "1 to 3", "at least 1".
      Returns:
      a human-readable description of the accepted argument count
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • min

      public int min()
      Returns the value of the min record component.
      Returns:
      the value of the min record component
    • max

      public int max()
      Returns the value of the max record component.
      Returns:
      the value of the max record component