Package fj
Class Ord<A>
- java.lang.Object
-
- fj.Ord<A>
-
public final class Ord<A> extends java.lang.Object
Tests for ordering between two objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Ord.AltDefinition<A>
Primitives functions of Ord: alternative minimal definition and overridable methods.static interface
Ord.Definition<A>
Primitives functions of Ord: minimal definition and overridable methods.(package private) class
Ord.OrdComparator
-
Field Summary
Fields Modifier and Type Field Description static Ord<java.math.BigDecimal>
bigdecimalOrd
An order instance for theBigDecimal
type.static Ord<java.math.BigInteger>
bigintOrd
An order instance for theBigInteger
type.static Ord<java.lang.Boolean>
booleanOrd
An order instance for theboolean
type.static Ord<java.lang.Byte>
byteOrd
An order instance for thebyte
type.static Ord<java.lang.Character>
charOrd
An order instance for thechar
type.private Ord.Definition<A>
def
static Ord<java.lang.Double>
doubleOrd
An order instance for thedouble
type.static Ord<java.lang.Float>
floatOrd
An order instance for thefloat
type.static Ord<java.lang.Integer>
intOrd
An order instance for theint
type.static Ord<java.lang.Long>
longOrd
An order instance for thelong
type.F<A,F<A,A>>
max
A function that returns the greater of its two arguments.F<A,F<A,A>>
min
A function that returns the lesser of its two arguments.static Ord<Natural>
naturalOrd
An order instance for theNatural
type.static Ord<Ordering>
orderingOrd
An order instance for theOrdering
type.static Ord<java.lang.Short>
shortOrd
An order instance for theshort
type.static Ord<java.lang.StringBuffer>
stringBufferOrd
An order instance for theStringBuffer
type.static Ord<java.lang.StringBuilder>
stringBuilderOrd
An order instance for theStringBuffer
type.static Ord<java.lang.String>
stringOrd
An order instance for theString
type.static Ord<Unit>
unitOrd
An order instance for theUnit
type.
-
Constructor Summary
Constructors Modifier Constructor Description private
Ord(Ord.Definition<A> def)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <A> Ord<Array<A>>
arrayOrd(Ord<A> oa)
An order instance for theArray
type.static <A extends java.lang.Comparable<A>>
Ord<A>comparableOrd()
An order instance for theComparable
interface.F<A,F<A,Ordering>>
compare()
First-class ordering.Ordering
compare(A a1, A a2)
Returns an ordering for the given arguments.static <A,B>
Ord<A>contramap(F<A,B> f, Ord<B> ord)
Static version ofcontramap(F)
<B> Ord<B>
contramap(F<B,A> f)
Maps the given function across this ord as a contra-variant functor.private static <A,B>
Ord.Definition<B>contramapDef(F<B,A> f, Ord.Definition<A> def)
static <A,B>
Ord<Either<A,B>>eitherOrd(Ord<A> oa, Ord<B> ob)
An order instance for theEither
type.boolean
eq(A a1, A a2)
Returnstrue
if the given arguments are equal,false
otherwise.Equal<A>
equal()
Returns anEqual
for this order.F<A,java.lang.Boolean>
isGreaterThan(A a)
Returns a function that returns true if its argument is greater than than the argument to this method.boolean
isGreaterThan(A a1, A a2)
Returnstrue
if the first given argument is greater than the second given argument,false
otherwise.F<A,java.lang.Boolean>
isLessThan(A a)
Returns a function that returns true if its argument is less than the argument to this method.boolean
isLessThan(A a1, A a2)
Returnstrue
if the first given argument is less than the second given argument,false
otherwise.boolean
isLessThanOrEqualTo(A a1, A a2)
Returnstrue
if the first given argument is less than or equal to the second given argument,false
otherwise.static <A> Ord<List<A>>
listOrd(Ord<A> oa)
An order instance for theList
type.A
max(A a1, A a2)
Returns the greater of its two arguments.Monoid<A>
maxMonoid(A zero)
Semigroup<A>
maxSemigroup()
A
min(A a1, A a2)
Returns the lesser of its two arguments.Monoid<A>
minMonoid(A zero)
Semigroup<A>
minSemigroup()
static <A> Ord<NonEmptyList<A>>
nonEmptyListOrd(Ord<A> oa)
An order instance for theNonEmptyList
type.static <A,B>
Ord.Definition<A>on(F<A,B> f, Ord<B> ord)
Begin definition of an ord instance.static <A> Ord<Option<A>>
optionOrd(Ord<A> oa)
An order instance for theOption
type.static <A> Ord<A>
ord(F<A,F<A,Ordering>> f)
Returns an order instance that uses the given equality test and ordering function.static <A> Ord<A>
ord(F2<A,A,Ordering> f)
Returns an order instance that uses the given equality test and ordering function.static <A> Ord<A>
ordDef(Ord.AltDefinition<A> def)
Returns an order instance that uses the given minimal equality test and ordering definition.static <A> Ord<A>
ordDef(Ord.Definition<A> def)
Returns an order instance that uses the given minimal equality test and ordering definition.static <A> Ord<P1<A>>
p1Ord(Ord<A> oa)
An order instance for a product-1.static <A,B>
Ord<P2<A,B>>p2Ord(Ord<A> oa, Ord<B> ob)
An order instance for a product-2, with the first factor considered most significant.static <A,B>
Ord<P2<A,B>>p2Ord1(Ord<A> oa)
static <A,B>
Ord<P2<A,B>>p2Ord2(Ord<B> ob)
static <A,B,C>
Ord<P3<A,B,C>>p3Ord(Ord<A> oa, Ord<B> ob, Ord<C> oc)
An order instance for a product-3, with the first factor considered most significant.Ord<A>
reverse()
static <A> Ord<Seq<A>>
seqOrd(Ord<A> ord)
Return a seq ord using the given value ord.static <A> Ord<Set<A>>
setOrd(Ord<A> oa)
An order instance for theSet
type.static <A> Ord<Stream<A>>
streamOrd(Ord<A> oa)
An order instance for theStream
type.java.util.Comparator<A>
toComparator()
static <A,B>
Ord<Validation<A,B>>validationOrd(Ord<A> oa, Ord<B> ob)
An order instance for theValidation
type.
-
-
-
Field Detail
-
def
private final Ord.Definition<A> def
-
booleanOrd
public static final Ord<java.lang.Boolean> booleanOrd
An order instance for theboolean
type.
-
byteOrd
public static final Ord<java.lang.Byte> byteOrd
An order instance for thebyte
type.
-
charOrd
public static final Ord<java.lang.Character> charOrd
An order instance for thechar
type.
-
doubleOrd
public static final Ord<java.lang.Double> doubleOrd
An order instance for thedouble
type.
-
floatOrd
public static final Ord<java.lang.Float> floatOrd
An order instance for thefloat
type.
-
intOrd
public static final Ord<java.lang.Integer> intOrd
An order instance for theint
type.
-
bigintOrd
public static final Ord<java.math.BigInteger> bigintOrd
An order instance for theBigInteger
type.
-
bigdecimalOrd
public static final Ord<java.math.BigDecimal> bigdecimalOrd
An order instance for theBigDecimal
type.
-
longOrd
public static final Ord<java.lang.Long> longOrd
An order instance for thelong
type.
-
shortOrd
public static final Ord<java.lang.Short> shortOrd
An order instance for theshort
type.
-
stringOrd
public static final Ord<java.lang.String> stringOrd
An order instance for theString
type.
-
stringBufferOrd
public static final Ord<java.lang.StringBuffer> stringBufferOrd
An order instance for theStringBuffer
type.
-
stringBuilderOrd
public static final Ord<java.lang.StringBuilder> stringBuilderOrd
An order instance for theStringBuffer
type.
-
-
Constructor Detail
-
Ord
private Ord(Ord.Definition<A> def)
-
-
Method Detail
-
compare
public F<A,F<A,Ordering>> compare()
First-class ordering.- Returns:
- A function that returns an ordering for its arguments.
-
compare
public Ordering compare(A a1, A a2)
Returns an ordering for the given arguments.- Parameters:
a1
- An instance to compare for ordering to another.a2
- An instance to compare for ordering to another.- Returns:
- An ordering for the given arguments.
-
eq
public boolean eq(A a1, A a2)
Returnstrue
if the given arguments are equal,false
otherwise.- Parameters:
a1
- An instance to compare for equality to another.a2
- An instance to compare for equality to another.- Returns:
true
if the given arguments are equal,false
otherwise.
-
contramap
public <B> Ord<B> contramap(F<B,A> f)
Maps the given function across this ord as a contra-variant functor.- Parameters:
f
- The function to map.- Returns:
- A new ord.
-
isLessThan
public boolean isLessThan(A a1, A a2)
Returnstrue
if the first given argument is less than the second given argument,false
otherwise.- Parameters:
a1
- An instance to compare for ordering to another.a2
- An instance to compare for ordering to another.- Returns:
true
if the first given argument is less than the second given argument,false
otherwise.
-
isLessThanOrEqualTo
public boolean isLessThanOrEqualTo(A a1, A a2)
Returnstrue
if the first given argument is less than or equal to the second given argument,false
otherwise.- Parameters:
a1
- An instance to compare for ordering to another.a2
- An instance to compare for ordering to another.- Returns:
true
if the first given argument is less than or equal to the second given argument,false
otherwise.
-
isGreaterThan
public boolean isGreaterThan(A a1, A a2)
Returnstrue
if the first given argument is greater than the second given argument,false
otherwise.- Parameters:
a1
- An instance to compare for ordering to another.a2
- An instance to compare for ordering to another.- Returns:
true
if the first given argument is greater than the second given argument,false
otherwise.
-
isLessThan
public F<A,java.lang.Boolean> isLessThan(A a)
Returns a function that returns true if its argument is less than the argument to this method.- Parameters:
a
- A value to compare against.- Returns:
- A function that returns true if its argument is less than the argument to this method.
-
isGreaterThan
public F<A,java.lang.Boolean> isGreaterThan(A a)
Returns a function that returns true if its argument is greater than than the argument to this method.- Parameters:
a
- A value to compare against.- Returns:
- A function that returns true if its argument is greater than the argument to this method.
-
max
public A max(A a1, A a2)
Returns the greater of its two arguments.- Parameters:
a1
- A value to compare with another.a2
- A value to compare with another.- Returns:
- The greater of the two values.
-
min
public A min(A a1, A a2)
Returns the lesser of its two arguments.- Parameters:
a1
- A value to compare with another.a2
- A value to compare with another.- Returns:
- The lesser of the two values.
-
on
public static <A,B> Ord.Definition<A> on(F<A,B> f, Ord<B> ord)
Begin definition of an ord instance.- See Also:
Equal.Definition.then(F, Equal)
-
contramap
public static <A,B> Ord<A> contramap(F<A,B> f, Ord<B> ord)
Static version ofcontramap(F)
-
contramapDef
private static <A,B> Ord.Definition<B> contramapDef(F<B,A> f, Ord.Definition<A> def)
-
ord
public static <A> Ord<A> ord(F<A,F<A,Ordering>> f)
Returns an order instance that uses the given equality test and ordering function. Java 8+ users: useordDef(Definition)
instead.- Parameters:
f
- The order function.- Returns:
- An order instance.
-
ord
public static <A> Ord<A> ord(F2<A,A,Ordering> f)
Returns an order instance that uses the given equality test and ordering function. Java 8+ users: useordDef(AltDefinition)
instead.- Parameters:
f
- The order function.- Returns:
- An order instance.
-
ordDef
public static <A> Ord<A> ordDef(Ord.Definition<A> def)
Returns an order instance that uses the given minimal equality test and ordering definition.- Parameters:
def
- The order definition.- Returns:
- An order instance.
-
ordDef
public static <A> Ord<A> ordDef(Ord.AltDefinition<A> def)
Returns an order instance that uses the given minimal equality test and ordering definition.- Parameters:
def
- The order definition.- Returns:
- An order instance.
-
optionOrd
public static <A> Ord<Option<A>> optionOrd(Ord<A> oa)
An order instance for theOption
type.- Parameters:
oa
- Order across the element of the option.- Returns:
- An order instance for the
Option
type.
-
eitherOrd
public static <A,B> Ord<Either<A,B>> eitherOrd(Ord<A> oa, Ord<B> ob)
An order instance for theEither
type.
-
validationOrd
public static <A,B> Ord<Validation<A,B>> validationOrd(Ord<A> oa, Ord<B> ob)
An order instance for theValidation
type.- Parameters:
oa
- Order across the failing side ofValidation
.ob
- Order across the succeeding side ofValidation
.- Returns:
- An order instance for the
Validation
type.
-
listOrd
public static <A> Ord<List<A>> listOrd(Ord<A> oa)
An order instance for theList
type.- Parameters:
oa
- Order across the elements of the list.- Returns:
- An order instance for the
List
type.
-
seqOrd
public static <A> Ord<Seq<A>> seqOrd(Ord<A> ord)
Return a seq ord using the given value ord.- Type Parameters:
A
- the type of the seq value- Parameters:
ord
- the given value ord- Returns:
- the seq ord
-
nonEmptyListOrd
public static <A> Ord<NonEmptyList<A>> nonEmptyListOrd(Ord<A> oa)
An order instance for theNonEmptyList
type.- Parameters:
oa
- Order across the elements of the non-empty list.- Returns:
- An order instance for the
NonEmptyList
type.
-
streamOrd
public static <A> Ord<Stream<A>> streamOrd(Ord<A> oa)
An order instance for theStream
type.- Parameters:
oa
- Order across the elements of the stream.- Returns:
- An order instance for the
Stream
type.
-
arrayOrd
public static <A> Ord<Array<A>> arrayOrd(Ord<A> oa)
An order instance for theArray
type.- Parameters:
oa
- Order across the elements of the array.- Returns:
- An order instance for the
Array
type.
-
setOrd
public static <A> Ord<Set<A>> setOrd(Ord<A> oa)
An order instance for theSet
type.- Parameters:
oa
- Order across the elements of the set.- Returns:
- An order instance for the
Set
type.
-
p1Ord
public static <A> Ord<P1<A>> p1Ord(Ord<A> oa)
An order instance for a product-1.- Parameters:
oa
- Order across the produced type.- Returns:
- An order instance for a product-1.
-
p2Ord
public static <A,B> Ord<P2<A,B>> p2Ord(Ord<A> oa, Ord<B> ob)
An order instance for a product-2, with the first factor considered most significant.- Parameters:
oa
- An order instance for the first factor.ob
- An order instance for the second factor.- Returns:
- An order instance for a product-2, with the first factor considered most significant.
-
p3Ord
public static <A,B,C> Ord<P3<A,B,C>> p3Ord(Ord<A> oa, Ord<B> ob, Ord<C> oc)
An order instance for a product-3, with the first factor considered most significant.- Parameters:
oa
- An order instance for the first factor.ob
- An order instance for the second factor.oc
- An order instance for the third factor.- Returns:
- An order instance for a product-3, with the first factor considered most significant.
-
comparableOrd
public static <A extends java.lang.Comparable<A>> Ord<A> comparableOrd()
An order instance for theComparable
interface.- Returns:
- An order instance for the
Comparable
interface.
-
toComparator
public java.util.Comparator<A> toComparator()
-
-