A trait representing a collection of elements in an unordered bag-like structure, a multi-set in other words. This collection allows duplicates and provides operations for adding elements, checking membership, and querying its properties such as size and emptiness.
Type parameters
- X
-
the type of elements contained in the bag. As a covariant type parameter,
Xallows subtypes of the specified type to be used in the bag.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait IterableOnce[X]class Objecttrait Matchableclass Any
- Known subtypes
-
class AbstractBag[X]class ListBag[X]
Members list
Value members
Abstract methods
Adds a new element to the bag, creating a new bag instance that includes the added element. The returned bag preserves all existing elements and includes the additional element.
Adds a new element to the bag, creating a new bag instance that includes the added element. The returned bag preserves all existing elements and includes the additional element.
Value parameters
- y
-
the element to be added to the bag. This element can be of the same type as the elements currently in the bag or a supertype of the bag's element type.
Attributes
- Returns
-
a new instance of
Bag[Y]containing all elements of the current bag and the added elementy.
Filters the elements of the Bag using the provided predicate function.
Filters the elements of the Bag using the provided predicate function.
This method returns a new Bag that contains only those elements for which the predicate function p evaluates to true.
Value parameters
- p
-
a predicate function that takes an element of type
Xand returns a boolean, indicating whether the element satisfies the condition or not.
Attributes
- Returns
-
an instance of
Bag[X]containing the elements that satisfy the predicate.
Concrete methods
Checks if the specified element is present in the collection.
Checks if the specified element is present in the collection.
Value parameters
- y
-
the element to check for presence; can be any type that is a supertype of
X.
Attributes
- Returns
-
trueif the element is found in the collection;falseotherwise.
Inherited methods
The number of elements in this collection, if it can be cheaply computed, -1 otherwise. Cheaply usually means: Not requiring a collection traversal.
The number of elements in this collection, if it can be cheaply computed, -1 otherwise. Cheaply usually means: Not requiring a collection traversal.
Attributes
- Inherited from:
- IterableOnce
Returns a scala.collection.Stepper for the elements of this collection.
Returns a scala.collection.Stepper for the elements of this collection.
The Stepper enables creating a Java stream to operate on the collection, see scala.jdk.StreamConverters. For collections holding primitive values, the Stepper can be used as an iterator which doesn't box the elements.
The implicit scala.collection.StepperShape parameter defines the resulting Stepper type according to the element type of this collection.
- For collections of
Int,Short,ByteorChar, an scala.collection.IntStepper is returned - For collections of
DoubleorFloat, a scala.collection.DoubleStepper is returned - For collections of
Longa scala.collection.LongStepper is returned - For any other element type, an scala.collection.AnyStepper is returned
Note that this method is overridden in subclasses and the return type is refined to S with EfficientSplit, for example scala.collection.IndexedSeqOps.stepper. For Steppers marked with scala.collection.Stepper.EfficientSplit, the converters in scala.jdk.StreamConverters allow creating parallel streams, whereas bare Steppers can be converted only to sequential streams.
Type parameters
- S
-
the type of the returned
Stepper, determined by the implicitStepperShape
Attributes
- Inherited from:
- IterableOnce
Inherited and Abstract methods
An scala.collection.Iterator over the elements of this collection.
An scala.collection.Iterator over the elements of this collection.
If an IterableOnce object is in fact an scala.collection.Iterator, this method always returns itself, in its current state, but if it is an scala.collection.Iterable, this method always returns a new scala.collection.Iterator.
Attributes
- Returns
-
an iterator over all elements of this collection
- Inherited from:
- IterableOnce