AbstractBag

com.phasmidsoftware.gryphon.core.AbstractBag
abstract class AbstractBag[+X](xs: Seq[X]) extends Bag[X]

An abstract implementation of the Bag trait that uses a Seq to store elements. This class provides a collection-like structure where elements can be added, and iteration over the stored elements is supported.

Type parameters

X

the type of elements contained within the AbstractBag[X]. The type is covariant to allow ListBag[A] to be used as ListBag[B] if A is a subtype of B.

Value parameters

xs

a sequence of elements of type X, representing the contents of this ListBag.

Attributes

Graph
Supertypes
trait Bag[X]
trait IterableOnce[X]
class Object
trait Matchable
class Any
Known subtypes
class ListBag[X]

Members list

Value members

Abstract methods

def unit[Z >: X](xs: Seq[Z]): Bag[Z]

Creates a new Bag containing the elements from the provided sequence.

Creates a new Bag containing the elements from the provided sequence.

Value parameters

xs

the sequence of elements to populate the new Bag. The type of elements in the sequence must be the same as or a supertype of the elements in the current context.

Attributes

Returns

a new instance of Bag[Z] containing the elements from the input sequence.

Concrete methods

def +[Y >: X](y: Y): Bag[Y]

Adds a new element to the bag, creating a new bag instance that includes the added element.

Adds a new element to the bag, creating a new bag instance that includes the added element.

Value parameters

y

the element to be added to the bag. The element can be of type Y, which must be a supertype of the elements currently present in the bag.

Attributes

Returns

a new instance of Bag[Y] that includes all elements of the current bag and the newly added element.

def filter(p: X => Boolean): Bag[X]

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 X and 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.

def iterator: Iterator[X]

Returns an iterator over the elements contained in this ListBag. The elements are iterated in a randomized order.

Returns an iterator over the elements contained in this ListBag. The elements are iterated in a randomized order.

Attributes

Returns

an Iterator[X] that provides a randomized traversal of the elements in the bag.

Inherited methods

def contains[Y >: X](y: Y): Boolean

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

true if the element is found in the collection; false otherwise.

Inherited from:
Bag
def knownSize: Int

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
def stepper[S <: Stepper[_]](implicit shape: StepperShape[X, S]): S

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, Byte or Char, an scala.collection.IntStepper is returned
  • For collections of Double or Float, a scala.collection.DoubleStepper is returned
  • For collections of Long a 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 implicit StepperShape

Attributes

Inherited from:
IterableOnce