Skip to content

Commit efff9a8

Browse files
committed
Add a factory method to Set that takes varargs (Set.set(A...)), comparable to what already exists in List.
1 parent cd14cec commit efff9a8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/src/main/java/fj/data/Set.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,18 @@ public static <A> Set<A> iterableSet(final Ord<A> o, final Iterable<A> as) {
454454
return s;
455455
}
456456

457+
/**
458+
* Constructs a set from the given elements.
459+
*
460+
* @param o An order for the elements of the new set.
461+
* @param as The elements to add to a set.
462+
* @return A new set containing the elements of the given iterable.
463+
*/
464+
public static <A> Set<A> set(final Ord<A> o, final A ... as) {
465+
Set<A> s = empty(o);
466+
for (final A a : as)
467+
s = s.insert(a);
468+
return s;
469+
}
470+
457471
}

0 commit comments

Comments
 (0)