001    // Copyright 2010, 2011 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    // http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.func;
016    
017    import java.util.Map;
018    
019    /**
020     * The result of the {@link Flow#zipWith(Flow)} method (or created from a Map via {@link F#zippedFlow(Map)}), a Flow of
021     * combined {@link Tuple} values (that can be deconstructed, eventually, using {@link #unzip()}).
022     * 
023     * @param <A>
024     * @param <B>
025     * @since 5.3
026     */
027    public interface ZippedFlow<A, B> extends FlowOperations<Tuple<A, B>, ZippedFlow<A, B>>
028    {
029        /**
030         * Mapping for zipped flows; a mapper is used to map tuples of this zipped flow into new tuples
031         * with a new type, forming the resulting zipped flow. This is a lazy operation.
032         */
033        <X, Y> ZippedFlow<X, Y> mapTuples(Mapper<Tuple<A, B>, Tuple<X, Y>> mapper);
034    
035        /**
036         * A ZippedFlow is a Flow of Tuples; this inverts that, splitting each Tuple into
037         * a Flow of elements, then assembling the result as a Tuple of two values. This is a lazy
038         * operation.
039         * 
040         * @return two flows of unzipped Tuples
041         */
042        Tuple<Flow<A>, Flow<B>> unzip();
043    
044        /**
045         * Returns a flow of the first values of the tuples of the zipped flow. This is a lazy
046         * operation.
047         */
048        Flow<A> firsts();
049    
050        /**
051         * Returns a flow of the second values of the tuples of the zipped flow. This is a lazy
052         * operation.
053         */
054        Flow<B> seconds();
055    
056        /**
057         * Filters the tuples in the zipped flow by applying a predicate to the first value in each tuple.
058         * This is a lazy operation.
059         */
060        ZippedFlow<A, B> filterOnFirst(Predicate<? super A> predicate);
061    
062        /**
063         * Filters the tuples in the zipped flow by applying a predicate to the second value in each tuple. This
064         * is a lazy operations.
065         */
066        ZippedFlow<A, B> filterOnSecond(Predicate<? super B> predicate);
067    
068        /**
069         * Removes tuples from the zipped flow by applying a predicate to the first value in each tuple.
070         * This is a lazy operation.
071         */
072        ZippedFlow<A, B> removeOnFirst(Predicate<? super A> predicate);
073    
074        /**
075         * Removes tuples from the zipped flow by applying a predicate to the second value in each tuple. This
076         * is a lazy operations.
077         */
078        ZippedFlow<A, B> removeOnSecond(Predicate<? super B> predicate);
079    
080        /**
081         * Constructs a HashMap by converting the tuples of the zipped flow into keys (first tuple value) and values (second
082         * tuple value).
083         */
084        Map<A, B> toMap();
085    }