11package fj .data ;
22
33import static fj .Bottom .error ;
4- import fj .F0 ;
5- import fj .F2Functions ;
4+
65import fj .Equal ;
7- import fj .F ;
8- import fj .F2 ;
9- import fj .Function ;
6+ import fj .F2Functions ;
107import fj .Hash ;
118import fj .Monoid ;
129import fj .Ord ;
10+ import fj .Ordering ;
1311import fj .P ;
1412import fj .P1 ;
15- import fj .P2 ;
1613import fj .Show ;
1714import fj .Unit ;
15+ import fj .P2 ;
16+ import fj .F0 ;
17+ import fj .F ;
18+ import fj .F2 ;
19+ import fj .Function ;
1820
1921import static fj .Function .*;
2022import static fj .P .p ;
3032import static fj .function .Booleans .not ;
3133import static fj .Ordering .GT ;
3234import static fj .Ord .intOrd ;
33- import fj .Ordering ;
35+
36+
3437import fj .control .Trampoline ;
3538import fj .control .parallel .Promise ;
3639import fj .control .parallel .Strategy ;
@@ -111,13 +114,19 @@ public final boolean isNotEmpty() {
111114
112115 /**
113116 * Performs a reduction on this list using the given arguments.
117+ * @deprecated As of release 4.5, use {@link #reduce}
114118 *
115119 * @param nil The value to return if this list is empty.
116120 * @param cons The function to apply to the head and tail of this list if it is not empty.
117121 * @return A reduction on this list.
118122 */
123+ @ Deprecated
119124 public final <B > B list (final B nil , final F <A , F <List <A >, B >> cons ) {
120- return isEmpty () ? nil : cons .f (head ()).f (tail ());
125+ return reduce (Function .uncurryF2 (cons ), nil );
126+ }
127+
128+ public final <B > B reduce (final F2 <A , List <A >, B > cons , final B nil ) {
129+ return isEmpty () ? nil : cons .f (head (), tail ());
121130 }
122131
123132 /**
@@ -143,10 +152,21 @@ public final List<A> orTail(final F0<List<A>> as) {
143152 /**
144153 * Returns an option projection of this list; <code>None</code> if empty, or the first element in
145154 * <code>Some</code>. Equivalent to {@link #headOption()}.
146- *
155+ * @deprecated As of release 4.5, use {@link #headOption()}
147156 * @return An option projection of this list.
148157 */
158+ @ Deprecated
149159 public final Option <A > toOption () {
160+ return headOption ();
161+
162+ }
163+
164+ /**
165+ * Returns the head of the list, if any. Equivalent to {@link #toOption()} .
166+ *
167+ * @return The optional head of the list.
168+ */
169+ public Option <A > headOption () {
150170 return isEmpty () ? Option .<A >none () : some (head ());
151171 }
152172
@@ -1134,14 +1154,6 @@ public static <A> F<List<A>, A> head_() {
11341154 return list -> list .head ();
11351155 }
11361156
1137- /**
1138- * Returns the head of the list, if any. Equivalent to {@link #toOption()} .
1139- *
1140- * @return The optional head of the list.
1141- */
1142- public Option <A > headOption () {
1143- return toOption ();
1144- }
11451157
11461158 /**
11471159 * Reutrns the tail of the list, if any.
@@ -1529,13 +1541,24 @@ private void tail(final List<A> tail) {
15291541 return Array .array (as ).toList ();
15301542 }
15311543
1532-
1544+ /**
1545+ * @deprecated As of release 4.5, use {@link #fromIterable(Iterable)}
1546+ */
1547+ @ Deprecated
15331548 public static <A > List <A > list (final Iterable <A > i ) {
1534- return iterableList (i );
1549+ return fromIterable (i );
15351550 }
15361551
1552+ /**
1553+ * @deprecated As of release 4.5, use {@link #fromIterator(Iterator)}
1554+ */
1555+ @ Deprecated
15371556 public static <A > List <A > list (final Iterator <A > it ) {
1538- return iterableList (() -> it );
1557+ return fromIterable (() -> it );
1558+ }
1559+
1560+ public static <A > List <A > fromIterator (final Iterator <A > it ) {
1561+ return fromIterable (() -> it );
15391562 }
15401563
15411564 /**
@@ -1840,20 +1863,24 @@ public static <A> F<Integer, F<List<A>, List<A>>> take() {
18401863
18411864 /**
18421865 * Takes the given iterable to a list.
1866+ * @deprecated From release 4.5 use {@link #fromIterable(Iterable)}
18431867 *
18441868 * @param i The iterable to take to a list.
18451869 * @return A list from the given iterable.
18461870 */
1871+ @ Deprecated
18471872 public static <A > List <A > iterableList (final Iterable <A > i ) {
1848- final Buffer <A > bs = empty ();
1873+ return fromIterable (i );
1874+ }
18491875
1850- for (final A a : i )
1876+ public static <A > List <A > fromIterable (final Iterable <A > i ) {
1877+ final Buffer <A > bs = empty ();
1878+ for (final A a : i ) {
18511879 bs .snoc (a );
1852-
1880+ }
18531881 return bs .toList ();
18541882 }
18551883
1856-
18571884 /**
18581885 * A mutable, singly linked list. This structure should be used <em>very</em> sparingly, in favour
18591886 * of the {@link List immutable singly linked list structure}.
@@ -2159,4 +2186,8 @@ public static <A> Prism<List<A>, P2<A, List<A>>> cons() {
21592186
21602187 }
21612188
2189+ public static final class Unsafe {
2190+
2191+ }
2192+
21622193}
0 commit comments