Question: Say, there is a class, Employee

```
@Getter
Class Employee {
    empId;
    empName;
    empDept;
}

```

I am trying to get a comma delimetered list of unique-departments from the list of employees in the String departments (Ex: 'Sales', 'Tech', 'Ops', 'Training')

```
List<Employee> employees = getListOfEmployees();
String departments = getUniqueDepartments(employees);

```

This is what I am trying:

```
String getUniqueDepartments(final List<Employee> employees) {
    return employees.stream().filter(emp -> emp.getEmpDept()!=null)
                      .map(emp -> String.format("'%s'", emp.getEmpDept()))
                      .collect(Collectors.joining(","))
}

```

How to add the distinct clause on top of this?

Answer: 
Simply, add the `distinct` intermediate operation before the `collect` reduction operation i.e:

```
...
...
.map(emp -> String.format("'%s'", emp.getEmpDept()))
.distinct()
.collect(Collectors.joining(","));

```
Or a little bit cleaner:

```
 employees
        .stream()
        .map(Employee::getEmpDept)
        .filter(Objects::nonNull)
        .map(x -> String.format("'%s'", x))
        .distinct()
        .collect(Collectors.joining(","));

```

Just notice that using the stateful intermediate operations (like `distinct` or `sorted`) will cancel all the laziness of the operations above it. Generally you should not care about this, but a good thing to keep in mind.