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
ASet
that 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
, anImmutableSet
provides 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 anImmutableSet
already contains only distinct values, this method always returns itself.static <A> ImmutableNonEmptySet<A>
of(A first, A... more)
Creates aImmutableNonEmptySet
with the given elements.default ImmutableSet<A>
toImmutable()
Returns anImmutableSet
containing the same elements as this one.default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptySet<A>>
toNonEmpty()
Attempts to convert thisImmutableSet
to anImmutableNonEmptySet
.default ImmutableNonEmptySet<A>
toNonEmptyOrThrow()
Attempts to convert thisImmutableSet
to 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 anImmutableSet
already contains only distinct values, this method always returns itself.
-
toImmutable
default ImmutableSet<A> toImmutable()
Returns anImmutableSet
containing the same elements as this one.Since this is an
ImmutableSet
already, this method simply returns itself.- Specified by:
toImmutable
in interfaceSet<A>
- Returns:
- itself
-
toNonEmpty
default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptySet<A>> toNonEmpty()
Attempts to convert thisImmutableSet
to anImmutableNonEmptySet
.If successful, returns a
ImmutableNonEmptySet
containing the same elements as this one, wrapped in aMaybe.just(A)
.If this
ImmutableSet
is empty, returnsMaybe.nothing()
.Does not make copies of any underlying data structures.
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.EnhancedIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.FiniteIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.ImmutableFiniteIterable<A>
- Specified by:
toNonEmpty
in interfacesoftware.kes.enhancediterables.ImmutableIterable<A>
- Specified by:
toNonEmpty
in interfaceSet<A>
- Returns:
- a
Maybe<ImmutableNonEmptySet<A>>
-
toNonEmptyOrThrow
default ImmutableNonEmptySet<A> toNonEmptyOrThrow()
Attempts to convert thisImmutableSet
to anImmutableNonEmptySet
.If successful, returns a
ImmutableNonEmptySet
containing the same elements as this one. Use this if you are confident that thisImmutableSet
is not empty.If this
ImmutableSet
is empty, throws anIllegalArgumentException
.Does not make copies of any underlying data structures.
- Specified by:
toNonEmptyOrThrow
in interfaceSet<A>
- Returns:
- an
ImmutableNonEmptySet<A>
- Throws:
java.lang.IllegalArgumentException
- if thisImmutableSet
is empty
-
of
@SafeVarargs static <A> ImmutableNonEmptySet<A> of(A first, A... more)
Creates aImmutableNonEmptySet
with the given elements.- Type Parameters:
A
- the element type- Parameters:
first
- the first elementmore
- the remaining elements- Returns:
- an
ImmutableNonEmptySet<A>
-
-