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

org.organicdesign.fp.collections.ImSet Maven / Gradle / Ivy

Go to download

Immutable Clojure collections and a Transformation abstraction for Java 8+, immutably, type-safely, and with good performance. Name will change to "Paguro" in November 2016.

There is a newer version: 2.0.13
Show newest version
// Copyright 2015-04-13 PlanBase Inc. & Glen Peterson
//
// 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 org.organicdesign.fp.collections;

/** An immutable set interface */
public interface ImSet extends UnmodSet {
    /** Adds an item, returning a modified version of the set (leaving the original set unchanged). */
    ImSet put(E e);

    /** Removes the given item, returning a modified version of the set (leaving the original set unchanged). */
    ImSet without(E key);

//    /**
//     A sequence of the items contained in this set.  Note that for some implementations, multiple calls to seq()
//     will yield sequences with different ordering of the same elements.
//     */
//    Sequence seq();

    default ImSet union(Iterable iter) {
        ImSet ret = this;
        for (E e : iter) { ret = ret.put(e); }
        return ret;
    }

    /** {@inheritDoc} */
    @Override UnmodIterator iterator();

    /**
     * This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards
     * compatibility in some performance-critical situations.  If you really need an array, consider using the somewhat
     * type-safe version of this method instead, but read the caveats first.
     * {@inheritDoc}
     */
    @Override default Object[] toArray() { return UnmodCollection.toArray(this); }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy