# Distinct¶

• Official ReactiveX documentation: Distinct
Observable.distinct(key_selector=None, comparer=None)

Returns an observable sequence that contains only distinct elements according to the key_selector and the comparer. Usage of this operator should be considered carefully due to the maintenance of an internal lookup structure which can grow large.

Example: res = obs = xs.distinct() obs = xs.distinct(lambda x: x.id) obs = xs.distinct(lambda x: x.id, lambda a,b: a == b)

Keyword arguments: key_selector – {Function} [Optional] A function to compute the

comparison key for each element.
comparer – {Function} [Optional] Used to compare items in the
collection.

Returns an observable {Observable} sequence only containing the distinct elements, based on a computed key value, from the source sequence.

Observable.distinct_until_changed(key_selector=None, comparer=None)

Returns an observable sequence that contains only distinct contiguous elements according to the key_selector and the comparer.

1 - obs = observable.distinct_until_changed(); 2 - obs = observable.distinct_until_changed(lambda x: x.id) 3 - obs = observable.distinct_until_changed(lambda x: x.id,

lambda x, y: x == y)
key_selector – [Optional] A function to compute the comparison key for
each element. If not provided, it projects the value.
comparer – [Optional] Equality comparer for computed key values. If
not provided, defaults to an equality comparer function.

Return An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.