<commit_before>part of nv.shared;

class CollectionView<E> extends _UnmodifiableListBase<E>
  with ChangeNotifierMixin implements ObservableList<E> {

  final ObservableList<E> _list;
  List<E> _view;

  Predicate<E> _filter = null;
  Sorter<E> _sorter = null;

  CollectionView(this._list) {
    assert(_list != null);
    _list.changes.listen(_list_changes);
  }

  int get length => _items.length;

  E operator [](int index) => _items[index];

  Predicate<E> get filter => _filter;

  void set filter(Predicate<E> value) {
    if(value != _filter) {
      _filter = value;
      _dirty();
    }
  }

  Sorter<E> get sorter => _sorter;

  void set sorter(Sorter<E> value) {
    if(value != _sorter) {
      _sorter = value;
      _dirty();
    }
  }

  //
  // Implementation
  //

  Predicate<int> get _effectivefilter {
    return (_filter == null) ? (E foo) => true : _filter;
  }

  List<E> get _items {
    if(_isDirty) {
      assert(_view == null);
      _view = _list.where(_effectivefilter).toList();
      if(_sorter != null) {
        _view.sort(_sorter);
      }
    }

    assert(!_isDirty);
    if(_view == null) {
      return _list;
    } else {
      return _view;<commit_msg>collection view gets 'dirty' every time filter or sorter are set<commit_after>part of nv.shared;

class CollectionView<E> extends _UnmodifiableListBase<E>
  with ChangeNotifierMixin implements ObservableList<E> {

  final ObservableList<E> _list;
  List<E> _view;

  Predicate<E> _filter = null;
  Sorter<E> _sorter = null;

  CollectionView(this._list) {
    assert(_list != null);
    _list.changes.listen(_list_changes);
  }

  int get length => _items.length;

  E operator [](int index) => _items[index];

  Predicate<E> get filter => _filter;

  void set filter(Predicate<E> value) {
    _filter = value;
    _dirty();
  }

  Sorter<E> get sorter => _sorter;

  void set sorter(Sorter<E> value) {
    _sorter = value;
    _dirty();
  }

  //
  // Implementation
  //

  Predicate<int> get _effectivefilter {
    return (_filter == null) ? (E foo) => true : _filter;
  }

  List<E> get _items {
    if(_isDirty) {
      assert(_view == null);
      _view = _list.where(_effectivefilter).toList();
      if(_sorter != null) {
        _view.sort(_sorter);
      }
    }

    assert(!_isDirty);
    if(_view == null) {
      return _list;
    } else {
      return _view;
{'fraction_non_alphanumeric': 0.13254537779653863, 'fraction_numerical': 0.0, 'mean_word_length': 2.8536585365853657, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4210363', 'n_tokens_mistral': 845, 'n_tokens_neox': 815, 'n_words': 187}