@@ -65,12 +65,66 @@ public static <A> Seq<A> single(final A a) {
6565 return new Seq <A >(Seq .<A >mkTree ().single (a ));
6666 }
6767
68+ /**
69+ * Constructs a sequence from the given elements.
70+ * @param as The elements to create the sequence from.
71+ * @return A sequence with the given elements.
72+ */
6873 @ SafeVarargs public static <A > Seq <A > seq (final A ... as ) {
69- return seq (List .list (as ));
74+ return fromList (List .list (as ));
7075 }
7176
77+ /**
78+ * Constructs a sequence from the given list.
79+ *
80+ * @deprecated As of release 4.5, use {@link #fromList(List)}
81+ *
82+ * @param list The list to create the sequence from.
83+ * @return A sequence with the given elements in the list.
84+ */
85+ @ Deprecated
7286 public static <A >Seq <A > seq (final List <A > list ) {
73- return list .foldLeft ((b , a ) -> b .snoc (a ), Seq .<A >empty ());
87+ return fromList (list );
88+ }
89+
90+ /**
91+ * Constructs a sequence from the given list.
92+ * @param list The list to create the sequence from.
93+ * @return A sequence with the elements of the list.
94+ */
95+ public static <A >Seq <A > fromList (final List <A > list ) {
96+ return fromIterable (list );
97+ }
98+
99+ /**
100+ * Constructs a sequence from the iterable.
101+ * @param i The iterable to create the sequence from.
102+ * @return A sequence with the elements of the iterable.
103+ */
104+ public static <A >Seq <A > fromIterable (final Iterable <A > i ) {
105+ Seq <A > s = Seq .empty ();
106+ for (final A a : i ) {
107+ s = s .snoc (a );
108+ }
109+ return s ;
110+ }
111+
112+ /**
113+ * Constructs a sequence from the iterator.
114+ * @param i The iterator to create the sequence from.
115+ * @return A sequence with the elements of the iterator.
116+ */
117+ public static <A >Seq <A > fromIterator (final Iterator <A > i ) {
118+ return fromIterable (() -> i );
119+ }
120+
121+ /**
122+ * Constructs a sequence from the given list.
123+ * @param list The list to create the sequence from.
124+ * @return A sequence with the elements of the list.
125+ */
126+ public static <A >Seq <A > fromJavaList (final java .util .List <A > list ) {
127+ return fromIterable (list );
74128 }
75129
76130 /**
@@ -145,6 +199,9 @@ public List<A> toList() {
145199 return buf .toList ();
146200 }
147201
202+ /**
203+ * Converts the sequence to a java.util.List
204+ */
148205 public final java .util .List <A > toJavaList () {
149206 return new AbstractList <A >() {
150207 @ Override public A get (int i ) { return index (i ); }
0 commit comments