# Gatherer.Integrator

Added in[API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Integrator

```
@FunctionalInterface interface Integrator<A : Any!, T : Any!, R : Any!>
```

|------------------------------------------------------------------------------------------------------------------------------|
| [java.util.stream.Gatherer.Integrator](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#) |

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Direct Subclasses [Gatherer.Integrator.Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy) |--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| | [Gatherer.Integrator.Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy) | Greedy Integrators consume all their input, and may only relay that the downstream does not want more elements. | |

An Integrator receives elements and processes them, optionally using the supplied state, and optionally sends incremental results downstream.

## Summary

|                                                                                                         Nested classes                                                                                                         ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract | [Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy) Greedy Integrators consume all their input, and may only relay that the downstream does not want more elements. |

|                                                                                                                                                                                                                                                                                                                                                                                                       Public methods                                                                                                                                                                                                                                                                                                                                                                                                        ||
|----------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                   | [integrate](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#integrate(java.util.stream.Gatherer.Integrator.A,%20java.util.stream.Gatherer.Integrator.T,%20java.util.stream.Gatherer.Downstream))`(`state:` `A`, `element:` `T`, `downstream:` `[Gatherer.Downstream](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Downstream)<in` `R>!`)` Performs an action given: the current state, the next element, and a downstream object; potentially inspecting and/or updating the state, optionally sending any number of elements downstream -- and then returns whether more elements are to be consumed or not. |
| openstatic[Gatherer.Integrator](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#)\<A,T,R\>!              | [of](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#of(java.util.stream.Gatherer.Integrator))`(`integrator:` `[Gatherer.Integrator](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#)<A,` `T,` `R>!`)` Factory method for turning Integrator-shaped lambdas into Integrators.                                                                                                                                                                                                                                                                                                                        |
| openstatic[Gatherer.Integrator.Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy)\<A,T,R\>! | [ofGreedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#ofGreedy(java.util.stream.Gatherer.Integrator.Greedy))`(`greedy:` `[Gatherer.Integrator.Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy)<A,` `T,` `R>!`)` Factory method for turning Integrator-shaped lambdas into[Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy)Integrators.                                                                                                                                                                                         |

## Public methods

### integrate

Added in[API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun integrate(
    state: A, 
    element: T, 
    downstream: Gatherer.Downstream<in R>!
): Boolean
```

Performs an action given: the current state, the next element, and a downstream object; potentially inspecting and/or updating the state, optionally sending any number of elements downstream -- and then returns whether more elements are to be consumed or not.

|                                                                                 Parameters                                                                                 ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `state`      | A:The state to integrate into                                                                                                                                |
| `element`    | T:The element to integrate                                                                                                                                   |
| `downstream` | [Gatherer.Downstream](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Downstream)\<inR\>!:The downstream object of this integration |

|                                                                    Return                                                                    ||
|------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true`if subsequent integration is desired,`false`if not |

### of

Added in[API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open static fun <A : Any!, T : Any!, R : Any!> of(integrator: Gatherer.Integrator<A, T, R>!): Gatherer.Integrator<A, T, R>!
```

Factory method for turning Integrator-shaped lambdas into Integrators.

|                                                                              Parameters                                                                              ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `integrator` | [Gatherer.Integrator](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#)\<A,T,R\>!:a lambda to create as Integrator |
| `<A>`        | the type of state used by this integrator                                                                                                              |
| `<T>`        | the type of elements this integrator receives                                                                                                          |
| `<R>`        | the type of results this integrator can produce                                                                                                        |

|                                                                            Return                                                                            ||
|---------------------------------------------------------------------------------------------------------------------------|-----------------------------------|
| [Gatherer.Integrator](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator#)<A,` `T,` `R>! | the given lambda as an Integrator |

### ofGreedy

Added in[API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open static fun <A : Any!, T : Any!, R : Any!> ofGreedy(greedy: Gatherer.Integrator.Greedy<A, T, R>!): Gatherer.Integrator.Greedy<A, T, R>!
```

Factory method for turning Integrator-shaped lambdas into[Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy)Integrators.

|                                                                                      Parameters                                                                                      ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `greedy` | [Gatherer.Integrator.Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy)\<A,T,R\>!:a lambda to create as Integrator.Greedy |
| `<A>`    | the type of state used by this integrator                                                                                                                                  |
| `<T>`    | the type of elements this integrator receives                                                                                                                              |
| `<R>`    | the type of results this integrator can produce                                                                                                                            |

|                                                                                     Return                                                                                      ||
|----------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------|
| [Gatherer.Integrator.Greedy](https://developer.android.com/reference/kotlin/java/util/stream/Gatherer.Integrator.Greedy)<A,` `T,` `R>! | the given lambda as a Greedy Integrator |