@@ -287,6 +287,39 @@ public final Ord<A> reverse() {
287287 return ordDef (def .dual ());
288288 }
289289
290+ /**
291+ * Constructs an ord instance, which compares using self and if objects are equal compares using <code>ord</code>
292+ *
293+ * @param ord Ord for subsequent comparison
294+ * @return A new equal instance
295+ */
296+ public final Ord <A > andThen (final Ord <A > ord ) {
297+ return ordDef ((a1 , a2 ) -> {
298+ final Ordering compareResult = compare (a1 , a2 );
299+ if (compareResult == Ordering .EQ )
300+ return ord .compare (a1 , a2 );
301+ return compareResult ;
302+ });
303+ }
304+
305+ /**
306+ * Constructs an ord instance, which compares using self and if objects are equal compares the mapped objects
307+ *
308+ * @param f The function to map the original object
309+ * @param ord Ord for the mapped object
310+ * @return A new equal instance
311+ */
312+ public final <B > Ord <A > andThen (final F <A , B > f , final Ord <B > ord ) {
313+ return andThen (ord .contramap (f ));
314+ }
315+
316+ /**
317+ * Static version of {@link #contramap(F)}
318+ */
319+ public static <A , B > Ord <A > contramap (final F <A , B > f , final Ord <B > ord ) {
320+ return ord .contramap (f );
321+ }
322+
290323 /**
291324 * Returns an order instance that uses the given equality test and ordering function.
292325 *
0 commit comments