Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.pre
Class Ord<A>

java.lang.Object
  extended by fj.pre.Ord<A>

public final class Ord<A>
extends Object

Tests for ordering between two objects.


Field Summary
static Ord<BigDecimal> bigdecimalOrd
          An order instance for the BigDecimal type.
static Ord<BigInteger> bigintOrd
          An order instance for the BigInteger type.
static Ord<Boolean> booleanOrd
          An order instance for the boolean type.
static Ord<Byte> byteOrd
          An order instance for the byte type.
static Ord<Character> charOrd
          An order instance for the char type.
static Ord<Double> doubleOrd
          An order instance for the double type.
static Ord<Float> floatOrd
          An order instance for the float type.
static Ord<Integer> intOrd
          An order instance for the int type.
static Ord<Long> longOrd
          An order instance for the long 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 the long type.
static Ord<Ordering> orderingOrd
          An order instance for the Ordering type.
static Ord<Short> shortOrd
          An order instance for the short type.
static Ord<StringBuffer> stringBufferOrd
          An order instance for the StringBuffer type.
static Ord<StringBuilder> stringBuilderOrd
          An order instance for the StringBuffer type.
static Ord<String> stringOrd
          An order instance for the String type.
static Ord<Unit> unitOrd
          An order instance for the Unit type.
 
Method Summary
static
<A> Ord<Array<A>>
arrayOrd(Ord<A> oa)
          An order instance for the Array type.
<B> Ord<B>
comap(F<B,A> f)
          Maps the given function across this ord as a contra-variant functor.
static
<A extends Comparable<A>>
Ord<A>
comparableOrd()
          An order instance for the Comparable 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<Either<A,B>>
eitherOrd(Ord<A> oa, Ord<B> ob)
          An order instance for the Either type.
 boolean eq(A a1, A a2)
          Returns true if the given arguments are equal, false otherwise.
 Equal<A> equal()
          Returns an Equal for this order.
 F<A,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)
          Returns true if the first given argument is greater than the second given argument, false otherwise.
 F<A,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)
          Returns true if the first given argument is less than the second given argument, false otherwise.
static
<A> Ord<List<A>>
listOrd(Ord<A> oa)
          An order instance for the List type.
 A max(A a1, A a2)
          Returns the greater of its two arguments.
 A min(A a1, A a2)
          Returns the lesser of its two arguments.
static
<A> Ord<NonEmptyList<A>>
nonEmptyListOrd(Ord<A> oa)
          An order instance for the NonEmptyList type.
static
<A> Ord<Option<A>>
optionOrd(Ord<A> oa)
          An order instance for the Option 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<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,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.
static
<A> Ord<Set<A>>
setOrd(Ord<A> oa)
          An order instance for the Set type.
static
<A> Ord<Stream<A>>
streamOrd(Ord<A> oa)
          An order instance for the Stream type.
static
<A,B> Ord<Validation<A,B>>
validationOrd(Ord<A> oa, Ord<B> ob)
          An order instance for the Validation type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max

public F<A,F<A,A>> max
A function that returns the greater of its two arguments.


min

public F<A,F<A,A>> min
A function that returns the lesser of its two arguments.


booleanOrd

public static final Ord<Boolean> booleanOrd
An order instance for the boolean type.


byteOrd

public static final Ord<Byte> byteOrd
An order instance for the byte type.


charOrd

public static final Ord<Character> charOrd
An order instance for the char type.


doubleOrd

public static final Ord<Double> doubleOrd
An order instance for the double type.


floatOrd

public static final Ord<Float> floatOrd
An order instance for the float type.


intOrd

public static final Ord<Integer> intOrd
An order instance for the int type.


bigintOrd

public static final Ord<BigInteger> bigintOrd
An order instance for the BigInteger type.


bigdecimalOrd

public static final Ord<BigDecimal> bigdecimalOrd
An order instance for the BigDecimal type.


longOrd

public static final Ord<Long> longOrd
An order instance for the long type.


shortOrd

public static final Ord<Short> shortOrd
An order instance for the short type.


orderingOrd

public static final Ord<Ordering> orderingOrd
An order instance for the Ordering type.


stringOrd

public static final Ord<String> stringOrd
An order instance for the String type.


stringBufferOrd

public static final Ord<StringBuffer> stringBufferOrd
An order instance for the StringBuffer type.


stringBuilderOrd

public static final Ord<StringBuilder> stringBuilderOrd
An order instance for the StringBuffer type.


unitOrd

public static final Ord<Unit> unitOrd
An order instance for the Unit type.


naturalOrd

public static final Ord<Natural> naturalOrd
An order instance for the long type.

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)
Returns true 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.

equal

public Equal<A> equal()
Returns an Equal for this order.

Returns:
An Equal for this order.

comap

public <B> Ord<B> comap(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)
Returns true 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.

isGreaterThan

public boolean isGreaterThan(A a1,
                             A a2)
Returns true 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,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,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.

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.

Parameters:
f - The order function.
Returns:
An order instance.

optionOrd

public static <A> Ord<Option<A>> optionOrd(Ord<A> oa)
An order instance for the Option 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 the Either type.

Parameters:
oa - Order across the left side of Either.
ob - Order across the right side of Either.
Returns:
An order instance for the Either type.

validationOrd

public static <A,B> Ord<Validation<A,B>> validationOrd(Ord<A> oa,
                                                       Ord<B> ob)
An order instance for the Validation type.

Parameters:
oa - Order across the failing side of Validation.
ob - Order across the succeeding side of Validation.
Returns:
An order instance for the Validation type.

listOrd

public static <A> Ord<List<A>> listOrd(Ord<A> oa)
An order instance for the List type.

Parameters:
oa - Order across the elements of the list.
Returns:
An order instance for the List type.

nonEmptyListOrd

public static <A> Ord<NonEmptyList<A>> nonEmptyListOrd(Ord<A> oa)
An order instance for the NonEmptyList 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 the Stream 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 the Array 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 the Set 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 Comparable<A>> Ord<A> comparableOrd()
An order instance for the Comparable interface.

Returns:
An order instance for the Comparable interface.

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.