# dedupeConsecutiveBy()

> Remove consecutive duplicates, where equality is measured by a given function.

---

Site [llms.txt](/gatherers4j/llms.txt)

---

### Implementation Notes

This function removes consecutive duplicate elements as measured by `Object::equals()`. For the purposes of this gatherer,
nulls are equal to each other but not equal to anything else.

For a version of `dedupeConsecutiveBy()` that measures equality via `Object::equals()`, see the [`dedupeConsecutive()`](/gatherers4j/gatherers/filtering-and-selection/dedupeconsecutive/) Gatherer.


**Signature**

`dedupeConsecutiveBy(Function<INPUT, Object> mappingFunction)`

* `mappingFunction` - A non-null `Function<INPUT, Object>` to compare elements of a `Stream<INPUT>`

### Diagram

![Marble diagram](../img/dedupe_consecutive_by-light.png)


### Examples

#### Remove consecutive duplicates using a function reference

```java
record Person(String firstName, String lastName) {}

Stream
    .of(
        new Person("Todd", "Ginsberg"),
        new Person("Todd", "Smith"),
        new Person("Emma", "Ginsberg")
    )
    .gather(Gatherers4j.dedupeConsecutiveBy(Person::firstName))
    .toList();

// [Person("Todd", "Ginsberg"), Person("Emma", "Ginsberg")]
```
