All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.marksman.collectionviews.ImmutableMappedVector Maven / Gradle / Ivy

There is a newer version: 1.2.3
Show newest version
package dev.marksman.collectionviews;

import com.jnape.palatable.lambda.functions.Fn1;

final class ImmutableMappedVector extends ConcreteVector
        implements ImmutableNonEmptyVector {

    private final MapperChain mapper;
    private final ImmutableNonEmptyVector underlying;

    ImmutableMappedVector(MapperChain mapper, ImmutableNonEmptyVector underlying) {
        this.mapper = mapper;
        this.underlying = underlying;
    }

    @Override
    public int size() {
        return underlying.size();
    }

    @SuppressWarnings("unchecked")
    @Override
    public A unsafeGet(int index) {
        return (A) mapper.apply(underlying.unsafeGet(index));
    }

    @SuppressWarnings("unchecked")
    @Override
    public  ImmutableMappedVector fmap(Fn1 f) {
        return new ImmutableMappedVector<>(mapper.add((Fn1) f),
                underlying);
    }

}