作用
去重。比較簡(jiǎn)單的作用,玩過(guò)數(shù)據(jù)庫(kù)的看到這個(gè)單詞應(yīng)該也挺眼熟的。
示例用法
Observable.just(1, 2, 1, 1, 2, 3, 4, 6, 4)
// Run on a background thread
.subscribeOn(Schedulers.io())
// Be notified on the main thread
.observeOn(AndroidSchedulers.mainThread())
.distinct()//就是去重操作
.subscribe(getObserver());//這里的觀察者依然不重要
運(yùn)行結(jié)果
1,2,3,4,6
分析
我們創(chuàng)建了一個(gè)會(huì)發(fā)送1, 2, 1, 1, 2, 3, 4, 6, 4 這些item的被觀察者
其中1,2,4都有重復(fù)的數(shù)字
然后用操作符distinct去掉重復(fù)的數(shù)字
最后,我們從觀察者中拿到的item為1,2,3,4,6
總結(jié)
這個(gè)系列只有干貨,如果大家有什么好的建議的話歡迎在下面評(píng)論?;蛘哂X(jué)得我哪里寫的不夠形象了,同樣可以提出來(lái)。