<commit_before>package com.googlecode.totallylazy.collections;

import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Filterable;
import com.googlecode.totallylazy.Foldable;
import com.googlecode.totallylazy.Function;
import com.googlecode.totallylazy.Function1;
import com.googlecode.totallylazy.Function2;
import com.googlecode.totallylazy.Functor;
import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Predicate;
import com.googlecode.totallylazy.Segment;
import com.googlecode.totallylazy.Sequence;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

import static com.googlecode.totallylazy.Callables.returns;
import static com.googlecode.totallylazy.Sequences.sequence;

public interface PersistentList<T> extends List<T>, PersistentCollection<T>, Iterable<T>, Segment<T>, Functor<T>, Indexed<T>, Foldable<T>, Filterable<T> {
    Option<T> find(Predicate<? super T> predicate);

    @Override
    PersistentList<T> empty();

    @Override
    PersistentList<T> cons(T head);

    @Override
    PersistentList<T> tail() throws NoSuchElementException;

    default PersistentList<PersistentList<T>> tails() {
        if(isEmpty()) return constructors.empty();
        return constructors.cons(this, tail().tails());
    }

    default T last() {
        if(tail().isEmpty()) return head();
        return tail().last();
    }

    default Option<T> lastOption() {
        if(isEmpty()) return Option.none();
        if(tail().isEmpty()) return headOption();
        return tail().lastOption();
    }

    PersistentList<T> append(T value);

    @Override
    PersistentList<T> delete(T value);

    PersistentList<T> deleteAll(Iterable<? extends T> values);

    PersistentList<T> reverse();<commit_msg>Made PersistentList.last[Option] tail recursive<commit_after>package com.googlecode.totallylazy.collections;

import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Filterable;
import com.googlecode.totallylazy.Foldable;
import com.googlecode.totallylazy.Function;
import com.googlecode.totallylazy.Function1;
import com.googlecode.totallylazy.Function2;
import com.googlecode.totallylazy.Functor;
import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Predicate;
import com.googlecode.totallylazy.Segment;
import com.googlecode.totallylazy.Sequence;
import com.googlecode.totallylazy.annotations.tailrec;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

import static com.googlecode.totallylazy.Callables.returns;
import static com.googlecode.totallylazy.Sequences.sequence;

public interface PersistentList<T> extends List<T>, PersistentCollection<T>, Iterable<T>, Segment<T>, Functor<T>, Indexed<T>, Foldable<T>, Filterable<T> {
    Option<T> find(Predicate<? super T> predicate);

    @Override
    PersistentList<T> empty();

    @Override
    PersistentList<T> cons(T head);

    @Override
    PersistentList<T> tail() throws NoSuchElementException;

    default PersistentList<PersistentList<T>> tails() {
        if(isEmpty()) return constructors.empty();
        return constructors.cons(this, tail().tails());
    }

    @tailrec
    default T last() {
        PersistentList<T> tail = tail();
        if(tail.isEmpty()) return head();
        return tail.last();
    }

    @tailrec
    default Option<T> lastOption() {
        if(isEmpty()) return Option.none();
        PersistentList<T> tail = tail();
        if(tail.isEmpty()) return headOption();
        return tail.lastOption();
    }

    PersistentList<T> append(T value);

    @Override
    PersistentList<T> delete(T value);

    PersistentList<T> deleteAll(Iterable<? extends T> values);

    PersistentList<T> reverse();
{'fraction_non_alphanumeric': 0.12092780818347668, 'fraction_numerical': 0.001563721657544957, 'mean_word_length': 4.652430044182622, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, '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': '3018753', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1171, 'n_words': 230}