# withType

abstract fun <S : T?> withType(type: Class<S>): DomainObjectCollection<S>

Returns a collection containing the objects in this collection of the given type. The returned collection is live, so that when matching objects are later added to this collection, they are also visible in the filtered collection.

This method is an intermediate operation. It does not change the realized/unrealized state of the elements in the collection.

#### Return

The matching objects. Returns an empty collection if there are no such objects in this collection.

#### Parameters

type

The type of objects to find.

abstract fun <S : T?> withType(type: Class<S>, configureAction: Action<in S>): DomainObjectCollection<S>

Returns a collection containing the objects in this collection of the given type. Equivalent to calling `withType(type).all(configureAction)`

This method is a terminal eager operation. It will cause the realization of all elements of this collection.

#### Return

The matching objects. Returns an empty collection if there are no such objects in this collection.

#### Parameters

type

The type of objects to find.

configureAction

The action to execute for each object in the resulting collection.

abstract fun <S : T?> withType(type: Class<S>, @DelegatesTo(genericTypeIndex = 0) configureClosure: Closure): DomainObjectCollection<S>

Returns a collection containing the objects in this collection of the given type. Equivalent to calling `withType(type).all(configureClosure)`.

This method is a terminal eager operation. It will cause the realization of all elements of this collection.

#### Return

The matching objects. Returns an empty collection if there are no such objects in this collection.

#### Parameters

type

The type of objects to find.

configureClosure

The closure to execute for each object in the resulting collection.