Package software.kes.collectionviews
Interface ImmutableSet<A>
-
- Type Parameters:
A- the element type
- All Superinterfaces:
software.kes.enhancediterables.EnhancedIterable<A>,software.kes.enhancediterables.FiniteIterable<A>,com.jnape.palatable.lambda.functor.Functor<A,software.kes.enhancediterables.EnhancedIterable<?>>,Immutable,software.kes.enhancediterables.ImmutableFiniteIterable<A>,software.kes.enhancediterables.ImmutableIterable<A>,java.lang.Iterable<A>,Set<A>
- All Known Subinterfaces:
ImmutableNonEmptySet<A>
public interface ImmutableSet<A> extends Set<A>, software.kes.enhancediterables.ImmutableFiniteIterable<A>, Immutable
ASetthat is guaranteed at compile-time to be safe from mutation anywhere. In other words, it owns the sole reference to the underlying collection.In addition to guarantees of
Set, anImmutableSetprovides the following benefits:toImmutable()always returns itself.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default ImmutableSet<A>distinct()Since anImmutableSetalready contains only distinct values, this method always returns itself.static <A> ImmutableNonEmptySet<A>of(A first, A... more)Creates aImmutableNonEmptySetwith the given elements.default ImmutableSet<A>toImmutable()Returns anImmutableSetcontaining the same elements as this one.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptySet<A>>toNonEmpty()Attempts to convert thisImmutableSetto anImmutableNonEmptySet.default ImmutableNonEmptySet<A>toNonEmptyOrThrow()Attempts to convert thisImmutableSetto anImmutableNonEmptySet.-
Methods inherited from interface software.kes.enhancediterables.EnhancedIterable
concat, concat, toArray, toCollection, zipWith, zipWith
-
Methods inherited from interface software.kes.enhancediterables.FiniteIterable
append, concat, concat, concat, cross, cross, drop, dropWhile, filter, fmap, foldLeft, foldRight, intersperse, magnetizeBy, partition, prepend, prependAll, slide, span, tails, takeWhile, toFinite, zipWith
-
Methods inherited from interface software.kes.enhancediterables.ImmutableFiniteIterable
append, concat, concat, cross, cycle, drop, dropWhile, filter, fmap, inits, intersperse, magnetizeBy, partition, prepend, prependAll, reverse, slide, span, tails, takeWhile, toFinite, zipWith
-
-
-
-
Method Detail
-
distinct
default ImmutableSet<A> distinct()
Since anImmutableSetalready contains only distinct values, this method always returns itself.
-
toImmutable
default ImmutableSet<A> toImmutable()
Returns anImmutableSetcontaining the same elements as this one.Since this is an
ImmutableSetalready, this method simply returns itself.- Specified by:
toImmutablein interfaceSet<A>- Returns:
- itself
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptySet<A>> toNonEmpty()
Attempts to convert thisImmutableSetto anImmutableNonEmptySet.If successful, returns a
ImmutableNonEmptySetcontaining the same elements as this one, wrapped in aMaybe.just(A).If this
ImmutableSetis empty, returnsMaybe.nothing().Does not make copies of any underlying data structures.
- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.EnhancedIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.FiniteIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>- Specified by:
toNonEmptyin interfacesoftware.kes.enhancediterables.ImmutableIterable<A>- Specified by:
toNonEmptyin interfaceSet<A>- Returns:
- a
Maybe<ImmutableNonEmptySet<A>>
-
toNonEmptyOrThrow
default ImmutableNonEmptySet<A> toNonEmptyOrThrow()
Attempts to convert thisImmutableSetto anImmutableNonEmptySet.If successful, returns a
ImmutableNonEmptySetcontaining the same elements as this one. Use this if you are confident that thisImmutableSetis not empty.If this
ImmutableSetis empty, throws anIllegalArgumentException.Does not make copies of any underlying data structures.
- Specified by:
toNonEmptyOrThrowin interfaceSet<A>- Returns:
- an
ImmutableNonEmptySet<A> - Throws:
java.lang.IllegalArgumentException- if thisImmutableSetis empty
-
of
@SafeVarargs static <A> ImmutableNonEmptySet<A> of(A first, A... more)
Creates aImmutableNonEmptySetwith the given elements.- Type Parameters:
A- the element type- Parameters:
first- the first elementmore- the remaining elements- Returns:
- an
ImmutableNonEmptySet<A>
-
-