![JAR search and dependency download from the Maven repository](/logo.png)
com.shapesecurity.functional.data.Nil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shape-functional-java Show documentation
Show all versions of shape-functional-java Show documentation
Functional programming library
/*
* 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 com.shapesecurity.functional.F;
import com.shapesecurity.functional.F2;
import com.shapesecurity.functional.Pair;
import org.jetbrains.annotations.NotNull;
public final class Nil extends ImmutableList {
private final static int DEFAULT_HASH_CODE;
static {
int h = HashCodeBuilder.init();
DEFAULT_HASH_CODE = HashCodeBuilder.put(h, "Nil");
}
Nil() {
super(0);
}
@Override
protected int calcHashCode() {
return DEFAULT_HASH_CODE;
}
@NotNull
@Override
public A foldLeft(@NotNull F2 f, @NotNull A init) {
return init;
}
@NotNull
@Override
public A foldRight(@NotNull F2 super T, A, A> f, @NotNull A init) {
return init;
}
@NotNull
@Override
public Maybe maybeHead() {
return Maybe.nothing();
}
@NotNull
@Override
public Maybe maybeLast() {
return Maybe.nothing();
}
@NotNull
@Override
public Maybe> maybeTail() {
return Maybe.nothing();
}
@NotNull
@Override
public Maybe> maybeInit() {
return Maybe.nothing();
}
@NotNull
@Override
public ImmutableList filter(@NotNull F f) {
return this;
}
@NotNull
@Override
public ImmutableList map(@NotNull F f) {
return nil();
}
@NotNull
@Override
public ImmutableList mapWithIndex(@NotNull F2 f) {
return nil();
}
@NotNull
@Override
public ImmutableList take(int n) {
return this;
}
@NotNull
@Override
public ImmutableList drop(int n) {
return this;
}
@NotNull
@Override
public Maybe> toNonEmptyList() {
return Maybe.nothing();
}
@NotNull
@Override
public Maybe decons(@NotNull F2, B> f) {
return Maybe.nothing();
}
@SuppressWarnings("unchecked")
@NotNull
@Override
public ImmutableList zipWith(@NotNull F2 f, @NotNull ImmutableList list) {
return (ImmutableList) this;
}
@Override
public boolean isEmpty() {
return true;
}
@NotNull
@Override
@SuppressWarnings("unchecked")
public ImmutableList append(@NotNull ImmutableList defaultClause) {
// This is safe due to erasure.
return (ImmutableList) defaultClause;
}
@Override
public boolean exists(@NotNull F f) {
return false;
}
@Override
public boolean contains(@NotNull T a) {
return false;
}
@NotNull
@Override
public Pair, ImmutableList> span(@NotNull F f) {
return new Pair<>(nil(), nil());
}
@NotNull
@Override
@SuppressWarnings("unchecked")
public ImmutableList flatMap(@NotNull F> f) {
return (ImmutableList) this;
}
@NotNull
@Override
public ImmutableList removeAll(@NotNull F f) {
return this;
}
@NotNull
@Override
public ImmutableList reverse() {
return this;
}
@NotNull
@SuppressWarnings("unchecked")
@Override
public ImmutableList patch(int index, int patchLength, @NotNull ImmutableList replacements) {
return (ImmutableList) replacements;
}
@NotNull
@Override
public Pair> mapAccumL(@NotNull F2> f, @NotNull B acc) {
return new Pair<>(acc, ImmutableList.nil());
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
return this == o;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy