removeDuplicate<E, P> function
list中根据某条属性去重 keepBehind=true 从后往前去重 保留后边
Implementation
List<E> removeDuplicate<E, P>(List<E> list, P Function(E element) getProperty,
{bool keepBehind = true}) {
var result = <E>[];
var iterator = keepBehind ? list.reversed.iterator : list.iterator;
final propertyCache = <P>{};
while (iterator.moveNext()) {
var e = iterator.current;
var p = getProperty(e);
if (!propertyCache.contains(p)) {
propertyCache.add(getProperty(e));
result.add(e);
}
}
return result;
}