<commit_before>import 'core-js/shim';
let IM = require('immutable');

class LLNode {
  //The alternative to this is using a record and storing pointers anyway...
  constructor(currentIndex = null, llStore = null){
    this._currentIndex = currentIndex;
    this._llStore = llStore;
    Object.freeze(this);
  }
  get data(){
    //memoize this function
    let has = this._llStore.has(this._currentIndex);
    return (has) ? this._llStore.get(this._currentIndex) : null;
  }
  get next(){
    //memoize
    let idx = this._currentIndex+1;
    let has = this._llStore.has(idx);
    return (has) ? new LLNode(idx, this._llStore) : null;
  }
}

export default class LinkedListBase {
  constructor(itemOrList = []) {
    this._lzStore = LinkedListBase.generateLzStore(itemOrList);
  }

  get store() {
    return this._lzStore.toJS();
  }

  get head() {
    return  this.size > 0 ? new LLNode(0, this._lzStore) : null;
  }

  get tail() {
    let size = this.size;
    return size > 0 ? new LLNode(size-1, this._lzStore) : null;
  }

  get size() {
    return this._lzStore.size;
  }

  prepend() {
    //RETURNS A LIST, new LZ Store

    //make new list:
    //head: data, next is this.head()
    //tail: this.tail()
    //lzStore: Use Cached result from previous call, and shift...
  }
  reverse(){
    //returns a list
    // head -> Tail
    // Tail -> Head, but modified to point to null
    // save Lz_store as reversed
  }

  addToTail(valueOrNode) {
    //refactor out into:
    //  isNode
    //  getNodeData
    let tailP = valueOrNode.__proto__;
    let maybeNode = (tailP && tailP === LinkedListBase.nodeConstructor);
    valueOrNode = (maybeNode) ? valueOrNode.data : valueOrNode; 
    let newList;
    if (this.tail) {
      newList = new LinkedListBase(this._lzStore.concat(valueOrNode).toJS());
    } else {
      newList = new LinkedListBase(valueOrNode);
    }

    return newList;
  }

  removeHead() {
    return new LinkedListBase(this._lzStore.rest().toJS());
  }

  contains(target) {
    return this._lzStore.contains(target);
  }

  traverse(cb) {
    this._lzStore.toArray().forEach(cb);
  }

  filter() {

  }

  insertBefore() {

  }

  insertAfter() {

  }

  removeBefore(){

  }

  removeAfter(){

  }

  static nodeConstructor() {
    return LLNode;
  }

  static generateLzStore(itemOrList) {
    return Array.isArray(itemOrList) ? IM.Seq(itemOrList) : IM.Seq([].concat(itemOrList));
  }

}<commit_msg>Feat: SLL, passes New Instance Initialization tests<commit_after>import 'core-js/shim';
let IM = require('immutable');

export default class LinkedListBase {
  constructor(itemOrList = []) {
    let items = Array.isArray(itemOrList) ? IM.Seq(itemOrList) :
      IM.Seq([].concat(itemOrList));
    this.head = LinkedListBase.makeHead(items);
    this.size = items.size;
  }

  static makeMap(data, next) {
    let node = {
      data: data, 
      next: next,
    };
    return Object.freeze(node);
  }
  
  static makeHead(seq) {
    let LLB = LinkedListBase;
    if (seq === null || seq.size === 0) { 
      return null; 
    } else {
      console.log(seq.size);
      let rest = seq.rest();
      rest = (rest.size === 0) ? null : rest;
      return LLB.makeMap(seq.first(), LLB.makeHead(rest));
    } 
  }

  get tail() {
    if (this.head === null) {
      return this.head;
    }else{
      let current = this.head;
      let tailNode;
      while (current !== null){
        if (current.next === null) { tailNode = current;}
        current = current.next; 
      }
      return tailNode;
    }
  }

  prepend() {
    //RETURNS A LIST, new LZ Store

    //make new list:
    //head: data, next is this.head()
    //tail: this.tail()
    //lzStore: Use Cached result from previous call, and shift...
  }
  reverse(){
    //returns a list
    // head -> Tail
    // Tail -> Head, but modified to point to null
    // save Lz_store as reversed
  }

  addToTail(valueOrNode) {
    //refactor out into:
    //  isNode
    //  getNodeData
    let tailP = valueOrNode.__proto__;
    let maybeNode = (tailP && tailP === LinkedListBase.nodeConstructor);
    valueOrNode = (maybeNode) ? valueOrNode.data : valueOrNode; 
    let newList;
    if (this.tail) {
      newList = new LinkedListBase(this._lzStore.concat(valueOrNode).toJS());
    } else {
      newList = new LinkedListBase(valueOrNode);
    }

    return newList;
  }

  removeHead() {
    return new LinkedListBase(this._lzStore.rest().toJS());
  }

  contains(target) {
    return this._lzStore.contains(target);
  }

  traverse(cb) {
    this._lzStore.toArray().forEach(cb);
  }

  filter() {

  }

  insertBefore() {

  }

  insertAfter() {

  }

  removeBefore(){

  }

  removeAfter(){

  }

  static nodeConstructor() {
    return LLNode;
  }

  static generateLzStore(itemOrList) {
    return 
  }

}
{'fraction_non_alphanumeric': 0.1373488953730721, 'fraction_numerical': 0.0014589412255106293, 'mean_word_length': 2.5390855457227137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6512541', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1629, 'n_words': 372}