# Trait differential_dataflow::operators::reduce::Reduce

source · ```
pub trait Reduce<G: Scope, K: Data, V: Data, R: Semigroup>{
// Required method
fn reduce_named<L, V2: Data, R2: Abelian>(
&self,
name: &str,
logic: L
) -> Collection<G, (K, V2), R2>
where L: FnMut(&K, &[(&V, R)], &mut Vec<(V2, R2)>) + 'static;
// Provided method
fn reduce<L, V2: Data, R2: Abelian>(
&self,
logic: L
) -> Collection<G, (K, V2), R2>
where L: FnMut(&K, &[(&V, R)], &mut Vec<(V2, R2)>) + 'static { ... }
}
```

## Expand description

Extension trait for the `reduce`

differential dataflow method.

## Required Methods§

## Provided Methods§

source#### fn reduce<L, V2: Data, R2: Abelian>(
&self,
logic: L
) -> Collection<G, (K, V2), R2>

#### fn reduce<L, V2: Data, R2: Abelian>( &self, logic: L ) -> Collection<G, (K, V2), R2>

Applies a reduction function on records grouped by key.

Input data must be structured as `(key, val)`

pairs.
The user-supplied reduction function takes as arguments

- a reference to the key,
- a reference to the slice of values and their accumulated updates,
- a mutuable reference to a vector to populate with output values and accumulated updates.

The user logic is only invoked for non-empty input collections, and it is safe to assume that the
slice of input values is non-empty. The values are presented in sorted order, as defined by their
`Ord`

implementations.

##### §Examples

```
use differential_dataflow::input::Input;
use differential_dataflow::operators::Reduce;
::timely::example(|scope| {
// report the smallest value for each group
scope.new_collection_from(1 .. 10).1
.map(|x| (x / 3, x))
.reduce(|_key, input, output| {
output.push((*input[0].0, 1))
});
});
```

## Object Safety§

This trait is

**not**object safe.