I want to remove all duplicate objects of one type from a list.
For Eg.
val models: MutableList<Model> = MutableList<DrawableModel>
models.add(Student)
models.add(Student)
models.add(Teacher)
models.add(Teacher)
models.add(Teacher)
Expected Output:
Student
Student
Teacher
I want only one instance of a teacher on the list.
I tried with
models.distinctBy{ it is Teacher}
But it is applying distinct to the entire list not to a particular object and returns.
Student
Teacher
Srudents in the expected output? An item at index 0 is the same as the item on index 1.Teacherin the list and allStudents stay?