<commit_before>import { Directive, Input, OnChanges, ViewContainerRef, TemplateRef, EmbeddedViewRef } from '@angular/core';

export interface ImplicitContext<T> {
  $implicit: T;
}

@Directive({
  selector: '[simpleFor], [simpleForOf]',
})
export class SimpleForOf<T> implements OnChanges {

  @Input()
  simpleForOf: T[];

  constructor(private viewContainer: ViewContainerRef, private template: TemplateRef<ImplicitContext<T>>) { }

  ngOnChanges() {
    const items = this.simpleForOf;

    const length = this.viewContainer.length;
    const newLength = items.length;

    // update existings
    for (let i = 0, l = Math.min(length, newLength); i < l; i++) {
      (<EmbeddedViewRef<ImplicitContext<T>>>this.viewContainer.get(i)).context.$implicit = items[i];
    }

    // add new
    for (let i = length; i < newLength; i++) {
      this.viewContainer.createEmbeddedView(this.template, {$implicit: items[i]});
    }

    // remove extraneous
    for (let i = length - 1; i >= newLength; i--) {
      this.viewContainer.remove(i);
    }
  }
}<commit_msg>feat: make simpleFor works with iterable and not just array also add index to context<commit_after>import { Directive, EmbeddedViewRef, Input, OnChanges, TemplateRef, ViewContainerRef } from '@angular/core';

export interface ImplicitContext<T> {
  index: number;
  $implicit: T;
}

@Directive({
  selector: '[simpleFor], [simpleForOf]',
})
export class SimpleForOf<T> implements OnChanges {

  @Input()
  simpleForOf: Iterable<T>;

  constructor(private viewContainer: ViewContainerRef, private template: TemplateRef<ImplicitContext<T>>) { }

  ngOnChanges() {
    const items = this.simpleForOf;

    const length = this.viewContainer.length;

    let it = items[Symbol.iterator]();

    let i = 0;
    let result: IteratorResult<T>;

    // update existing
    while ((result = it.next()).done !== true && i < length) {
      const context = (<EmbeddedViewRef<ImplicitContext<T>>>this.viewContainer.get(i)).context;
      context.index = i;
      context.$implicit = items[i];
      i++;
    }

    if (result.done !== true) {
      // add new
      do {
        this.viewContainer.createEmbeddedView(this.template, {$implicit: items[i], index: i});
        i++;
      } while ((result = it.next()).done !== true)
    } else {
      // remove extraneous
      for (; i < length; i++) {
        this.viewContainer.remove(i);
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.142975893599335, 'fraction_numerical': 0.0012468827930174563, 'mean_word_length': 3.40036563071298, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 20, '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': '4375932', 'n_tokens_mistral': 769, 'n_tokens_neox': 744, 'n_words': 183}