com.shapesecurity.functional.data.ImmutableList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shift Show documentation
Show all versions of shift Show documentation
Shift format ECMAScript 6 AST tooling
/*
* Copyright 2014 Shape Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.shapesecurity.functional.data;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.shapesecurity.functional.Effect;
import com.shapesecurity.functional.F;
import com.shapesecurity.functional.F2;
import com.shapesecurity.functional.Pair;
import com.shapesecurity.functional.Thunk;
import org.jetbrains.annotations.NotNull;
/**
* An immutable singly linked list implementation. None of the operations in {@link ImmutableList} changes the list itself. Therefore you can freely share the list in
* your system.
*
* This is a "classical" list implementation that the list is only allowed to prepend and to remove the first element efficiently.
* Therefore it is essentially equivalent to a stack.
*
* It is either an empty list, or a record that contains the first element (called "head") and a list that follows(called "tail").
* With the assumption that all the elements in the list are also immutable, the sharing of the tails is possible.
*
* For a data structure that allows O(1) concatenation, try {@link ConcatList}. A BinaryTree can be converted into a List in O(n) time.
*
* @param The super type of all the elements.
*/
public abstract class ImmutableList implements Iterable {
private static final ImmutableList