public abstract class CollectionPatterns extends Object
Iterable,
Collection| Modifier and Type | Method and Description |
|---|---|
static <A> Pattern<A[]> |
anyArrayElement(Pattern<? super A> p)
Returns a pattern that matches a given pattern for any element
of an array successively.
|
static <A> Motif<A,Iterable<? extends A>> |
anyElement() |
static <A> Pattern<Iterable<? extends A>> |
anyElement(Pattern<? super A> p)
Returns a pattern that matches a given pattern for any element
of an
Iterable successively. |
static <A> Pattern<? super List<? extends A>> |
cons(Pattern<? super A> first,
Pattern<? super List<? extends A>> rest) |
static <A> Pattern<List<? extends A>> |
elementwise(List<? extends Pattern<? super A>> ps)
Returns a pattern that matches a given list of patterns
element-by-element against a list.
|
static <A> Pattern<A[]> |
elementwise(Pattern<? super A>... ps)
Returns a pattern that matches a given array of patterns
element-by-element against an array.
|
static <A> Pattern<A[]> |
firstArrayElement(Pattern<? super A> p)
Returns a pattern that matches a given pattern for the first
matching element of an array.
|
static <A> Pattern<Iterable<? extends A>> |
firstElement(Pattern<? super A> p)
Returns a pattern that matches a given pattern for the first
matching element of an
Iterable. |
static <A> Pattern<A> |
from(Set<? super A> set)
Returns a pattern that matches against elements from a given
set.
|
static <A,B> Pattern<Map<A,B>> |
get(A key,
Pattern<? super B> body)
Returns a pattern that matches a given pattern against the
element for a given key in a
Map. |
static <A> Pattern<List<? extends A>> |
get(int index,
Pattern<? super A> body)
Returns a pattern that matches a given pattern against the
element at a given index in a
List. |
static <A> Pattern<A[]> |
getArray(int index,
Pattern<? super A> body)
Returns a pattern that matches a given pattern against the
element at a given index in an array.
|
static <A> Pattern<Map<A,?>> |
keySet(Pattern<? super Set<? extends A>> p)
Returns a pattern that matches a given pattern against the key set of a map.
|
static <A> Pattern<A[]> |
length(Pattern<? super Integer> body)
Returns a pattern that matches a given pattern against the length
of an array.
|
static <A,B> Motif<List<? extends A>,List<? extends B>> |
map(Motif<A,B> m) |
static <A> Pattern<? super List<? extends A>> |
nil() |
static <A> Pattern<? super Collection<? extends A>> |
singleton(Pattern<? super A> p)
Returns a pattern that matches a given pattern against the
(single) element of a list.
|
static <A> Pattern<Collection<? extends A>> |
size(Pattern<? super Integer> body)
Returns a pattern that matches a given pattern against the size
of a
Collection. |
static <A> Pattern<? super List<? extends A>> |
snoc(Pattern<? super List<? extends A>> front,
Pattern<? super A> last) |
static <A> Pattern<Map<?,A>> |
values(Pattern<? super Collection<? extends A>> p)
Returns a pattern that matches a given pattern against the values of a map.
|
public static <A> Pattern<Iterable<? extends A>> anyElement(Pattern<? super A> p)
Iterable successively. Matches are
effected exhaustively for each element returned by the java.lang.Iterable's Iterator before
proceeding to the next element.p - the pattern to match against the elements of the Iterable.firstElement(Pattern),
anyArrayElement(Pattern)public static <A> Pattern<Iterable<? extends A>> firstElement(Pattern<? super A> p)
Iterable. Elements
returned by the Iterable's java.util.Iterator are tried in order until one has at least one
match; matches for that element are effected exhaustively and
only.p - the pattern to match against the elements of the Iterable.anyElement(Pattern),
firstArrayElement(Pattern)public static <A> Pattern<A[]> anyArrayElement(Pattern<? super A> p)
p - the pattern to match against the elements of the array.firstArrayElement(Pattern),
anyElement(Pattern)public static <A> Pattern<A[]> firstArrayElement(Pattern<? super A> p)
p - the pattern to match against the elements of the array.anyArrayElement(Pattern),
firstElement(Pattern)public static <A> Pattern<Map<A,?>> keySet(Pattern<? super Set<? extends A>> p)
p - the pattern to match against the key set.Map.keySet()public static <A> Pattern<Map<?,A>> values(Pattern<? super Collection<? extends A>> p)
p - the pattern to match against the values.Map.values()public static <A> Pattern<Collection<? extends A>> size(Pattern<? super Integer> body)
Collection.body - the pattern to match against the size.Collection.size()public static <A> Pattern<List<? extends A>> get(int index, Pattern<? super A> body)
List.
The failure behaviour of the resulting pattern reflects that
of List.get(int): if the given index is invalid for
a target list, an IndexOutOfBoundsException is thrown
during matching.
index - the index of the element to select.body - the pattern to match against the selected element.List.get(int)public static <A,B> Pattern<Map<A,B>> get(A key, Pattern<? super B> body)
Map.
The failure behaviour of the resulting pattern reflects that
of Map.get(java.lang.Object): if the given key is not contained in
a target list, the body pattern is matched against null.
key - the key of the element to select.body - the pattern to match against the selected element.Map.get(java.lang.Object)public static <A> Pattern<A[]> length(Pattern<? super Integer> body)
body - the pattern to match against the length.public static <A> Pattern<A[]> getArray(int index, Pattern<? super A> body)
The failure behaviour of the resulting pattern reflects that
of array selection: if the given index is invalid for
a target array, an ArrayIndexOutOfBoundsException is thrown
during matching.
index - the index of the element to select.body - the pattern to match against the selected element.public static <A> Pattern<List<? extends A>> elementwise(List<? extends Pattern<? super A>> ps)
Pattern.all(Pattern...).ps - a list of patterns to match against list elements.public static <A> Pattern<A[]> elementwise(Pattern<? super A>... ps)
Pattern.all(Pattern...).ps - an array of patterns to match against array elements.public static <A> Pattern<A> from(Set<? super A> set)
A pattern returned by this method is deterministic and binds no variables.
set - the set of elements to match.Set.contains(Object)public static <A> Pattern<? super Collection<? extends A>> singleton(Pattern<? super A> p)
ps - a patterns to match against the list element.public static <A> Pattern<? super List<? extends A>> cons(Pattern<? super A> first, Pattern<? super List<? extends A>> rest)
public static <A> Pattern<? super List<? extends A>> snoc(Pattern<? super List<? extends A>> front, Pattern<? super A> last)
see also the complete user documentation .