Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/src/main/java/fj/Ord.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,25 @@ public Ordering f(final A a2) {
}
});
}

/**
* An order instance that uses {@link Object#hashCode()} for computing the order.
*
* @return An order instance that is based on {@link Object#hashCode()}.
*/
public static <A> Ord<A> hashOrd() {
return Ord.<A> ord(new F<A, F<A, Ordering>>() {
@Override
public F<A, Ordering> f(final A a) {
return new F<A, Ordering>() {
@Override
public Ordering f(final A a2) {
final int x = a.hashCode() - a2.hashCode();
return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT;
}
};
}
});
}

}
10 changes: 10 additions & 0 deletions core/src/main/java/fj/function/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ private Strings() {
throw new UnsupportedOperationException();
}

/**
* This function checks if a given String is neither <code>null</code> nor empty.
*/
public static final F<String, Boolean> isNotNullOrEmpty = new F<String, Boolean>() {
@Override
public Boolean f(final String a) {
return a != null && a.length() > 0;
}
};

/**
* A curried version of {@link String#isEmpty()}.
*/
Expand Down