File tree Expand file tree Collapse file tree 3 files changed +638
-25
lines changed Expand file tree Collapse file tree 3 files changed +638
-25
lines changed Original file line number Diff line number Diff line change 1
1
package fj ;
2
2
3
- import fj .data .Array ;
4
- import fj .data .Either ;
5
- import fj .data .List ;
6
- import fj .data .Natural ;
7
- import fj .data .NonEmptyList ;
8
- import fj .data .Option ;
9
- import fj .data .Set ;
10
- import fj .data .Stream ;
11
- import fj .data .Validation ;
12
-
13
- import java .math .BigDecimal ;
14
- import java .math .BigInteger ;
3
+ import fj .data .*;
4
+
5
+ import java .math .*;
15
6
import java .util .Comparator ;
16
7
17
- import static fj .Function .apply ;
18
- import static fj .Function .compose ;
19
- import static fj .Function .curry ;
20
- import static fj .Semigroup .semigroup ;
8
+ import static fj .Function .*;
21
9
import static fj .Semigroup .semigroupDef ;
22
10
23
11
/**
@@ -541,6 +529,37 @@ public static <A> Ord<List<A>> listOrd(final Ord<A> oa) {
541
529
});
542
530
}
543
531
532
+ /**
533
+ * Return a seq ord using the given value ord.
534
+ *
535
+ * @param ord the given value ord
536
+ * @param <A> the type of the seq value
537
+ * @return the seq ord
538
+ */
539
+ public static <A > Ord <Seq <A >> seqOrd (final Ord <A > ord ) {
540
+ return ordDef ((l1 , l2 ) -> {
541
+ Seq <A > x1 = l1 ;
542
+ Seq <A > x2 = l2 ;
543
+
544
+ while (x1 .isNotEmpty () && x2 .isNotEmpty ()) {
545
+ final Ordering o = ord .compare (x1 .head (), x2 .head ());
546
+ if (o == Ordering .LT || o == Ordering .GT ) {
547
+ return o ;
548
+ }
549
+ x1 = x1 .tail ();
550
+ x2 = x2 .tail ();
551
+ }
552
+
553
+ if (x1 .isEmpty () && x2 .isEmpty ()) {
554
+ return Ordering .EQ ;
555
+ } else if (x1 .isEmpty ()) {
556
+ return Ordering .LT ;
557
+ } else {
558
+ return Ordering .GT ;
559
+ }
560
+ });
561
+ }
562
+
544
563
/**
545
564
* An order instance for the {@link NonEmptyList} type.
546
565
*
You can’t perform that action at this time.
0 commit comments