Java Code Examples for com.googlecode.totallylazy.Pair#pair()

The following examples show how to use com.googlecode.totallylazy.Pair#pair() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Monoid.java    From totallylazy with Apache License 2.0 5 votes vote down vote up
public static <A, B> CurriedMonoid<Pair<A, B>> pair(final Monoid<A> aMonoid, final Monoid<B> bMonoid) {
    return new CurriedMonoid<Pair<A, B>>() {
        @Override
        public Pair<A, B> call(Pair<A, B> a, Pair<A, B> b) throws Exception {
            return Pair.pair(aMonoid.call(a.first(), b.first()), bMonoid.call(a.second(), b.second()));
        }

        @Override
        public Pair<A, B> identity() {
            return Pair.pair(aMonoid.identity(), bMonoid.identity());
        }
    };
}
 
Example 2
Source File: Command.java    From java-repl with Apache License 2.0 5 votes vote down vote up
public static final Pair<String, Option<Integer>> parseNumericCommand(String input) {
    final Sequence<String> splitInput = sequence(input.split(COMMAND_SEPARATOR));

    try {
        return Pair.pair(splitInput.first(), some(parseInt(splitInput.tail().toString(COMMAND_SEPARATOR))));
    } catch (Exception e) {
        return Pair.pair(splitInput.first(), none(Integer.class));
    }
}
 
Example 3
Source File: PersistentMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public static <K, V, M extends PersistentMap<K, V>> Pair<M, Option<V>> put(M map, K key, V newValue) {
    return Pair.pair(Unchecked.<M>cast(map.insert(key, newValue)), map.lookup(key));
}
 
Example 4
Source File: PersistentMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public static <K, V, M extends PersistentMap<K, V>> Pair<M, Option<V>> remove(M map, K key) {
    return Pair.pair(Unchecked.<M>cast(map.delete(key)), map.lookup(key));
}
 
Example 5
Source File: TreeSet.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
private Pair<PersistentSortedSet<T>, T> treeSet(Pair<? extends PersistentSortedMap<T, T>, Pair<T, T>> pair) {
    return Pair.pair(treeSet(pair.first()), pair.second().first());
}
 
Example 6
Source File: TreeSet.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
private Pair<T, T> pair(Object head) {
    return Pair.pair(Unchecked.<T>cast(head), Unchecked.<T>cast(head));
}
 
Example 7
Source File: AbstractTreeMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Override
public Pair<Self, Pair<K, V>> removeFirst() {
    if (left.isEmpty()) return Pair.pair(right, pair());
    final Pair<? extends TreeMap<K, V>, Pair<K, V>> newLeft = left.removeFirst();
    return Pair.pair(create(comparator, key, value, newLeft.first(), right), newLeft.second());
}
 
Example 8
Source File: AbstractTreeMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Override
public Pair<Self, Pair<K, V>> removeLast() {
    if (right.isEmpty()) return Pair.pair(left, pair());
    final Pair<? extends TreeMap<K, V>, Pair<K, V>> newRight = right.removeLast();
    return Pair.pair(create(comparator, key, value, left, newRight.first()), newRight.second());
}
 
Example 9
Source File: AbstractTreeMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
protected Pair<K, V> pair() {
    return Pair.pair(key, value);
}
 
Example 10
Source File: TreeZipper.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public Pair<K, V> pair() {
    return Pair.pair(focus.key(), focus.value());
}
 
Example 11
Source File: FileSource.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public static Function1<File, Pair<String, File>> relativeTo(final File folder) {
    return file -> Pair.pair(Files.relativePath(folder, file), file);
}
 
Example 12
Source File: PersistentSortedMapTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public static Function1<Integer, Pair<Integer, Integer>> asPair() {
    return integer -> Pair.pair(integer, integer);
}
 
Example 13
Source File: PersistentMapTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public static Function1<Integer, Pair<Integer, Integer>> asPair() {
    return integer -> Pair.pair(integer, integer);
}
 
Example 14
Source File: Command.java    From java-repl with Apache License 2.0 4 votes vote down vote up
public static final Pair<String, Option<String>> parseStringCommand(String input) {
    final Sequence<String> splitInput = sequence(input.split(COMMAND_SEPARATOR));
    String command = splitInput.first();
    String value = splitInput.tail().toString(COMMAND_SEPARATOR);
    return Pair.pair(command, value.isEmpty() ? Option.none(String.class) : some(value));
}