Record Class Arity
java.lang.Object
java.lang.Record
com.darkcollective.relix.function.Arity
- Record Components:
min- the smallest number of arguments accepted; zero or moremax- the largest number accepted, orUNBOUNDEDfor no limit; when bounded, never smaller thanmin
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccepts(int count) static ArityatLeast(int min) At leastminarguments, with no upper limit.static Aritybetween(int min, int max) Betweenminandmaxarguments, inclusive.describe()Renders the range the way an error message wants it —"2","1 to 3","at least 1".final booleanIndicates whether some other object is "equal to" this one.static Arityexactly(int count) Exactlycountarguments — the common case.final inthashCode()Returns a hash code value for this object.booleanintmax()Returns the value of themaxrecord component.intmin()Returns the value of theminrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
UNBOUNDED
public static final int UNBOUNDEDThe valuemax()takes when a function accepts any number of arguments.- See Also:
-
-
Constructor Details
-
Method Details
-
exactly
Exactlycountarguments — the common case.- Parameters:
count- the required number of arguments- Returns:
- the fixed arity
-
between
Betweenminandmaxarguments, inclusive.- Parameters:
min- the smallest number acceptedmax- the largest number accepted- Returns:
- the bounded range
-
atLeast
At leastminarguments, with no upper limit.- Parameters:
min- the smallest number accepted- Returns:
- the open-ended range
-
isUnbounded
public boolean isUnbounded()- Returns:
truewhen there is no upper limit on the argument count
-
accepts
public boolean accepts(int count) - Parameters:
count- a candidate number of arguments- Returns:
truewhen a call withcountarguments is within range
-
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
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. -
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. -
equals
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 '=='. -
min
public int min()Returns the value of theminrecord component.- Returns:
- the value of the
minrecord component
-
max
public int max()Returns the value of themaxrecord component.- Returns:
- the value of the
maxrecord component
-