Package eu.bandm.tools.paisley
Class CollectionPatterns
java.lang.Object
eu.bandm.tools.paisley.CollectionPatterns
Static factory methods for creating patterns for collections.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A> Pattern<A[]> anyArrayElement(Pattern<? super A> p) Returns a pattern that matches a given pattern for any element of an array successively.anyElement(Pattern<? super A> p) Returns a pattern that matches a given pattern for any element of anIterablesuccessively.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.elementwise(List<Pattern<? super A>> ps) Returns a pattern that matches a given list of patterns element-by-element against a list.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.firstElement(Pattern<? super A> p) Returns a pattern that matches a given pattern for the first matching element of anIterable.static <A> Pattern<A> Returns a pattern that matches against elements from a given set.Returns a pattern that matches a given pattern against the element at a given index in aList.Returns a pattern that matches a given pattern against the element for a given key in aMap.static <A> Pattern<A[]> Returns a pattern that matches a given pattern against the element at a given index in an array.Returns a pattern that matches a given pattern against the key set of a map.static <A> Pattern<A[]> Returns a pattern that matches a given pattern against the length of an array.nil()static <A> Pattern<Collection<A>> Returns a pattern that matches a given pattern against the (single) element of a list.static <A> Pattern<Collection<A>> Returns a pattern that matches a given pattern against the size of aCollection.values(Pattern<? super Collection<B>> p) Returns a pattern that matches a given pattern against the values of a map.
-
Method Details
-
anyElement
Returns a pattern that matches a given pattern for any element of anIterablesuccessively. Matches are effected exhaustively for each element returned by thejava.lang.Iterable'sIteratorbefore proceeding to the next element.- Parameters:
p- the pattern to match against the elements of theIterable.- See Also:
-
anyElement
-
firstElement
Returns a pattern that matches a given pattern for the first matching element of anIterable. Elements returned by theIterable'sjava.util.Iteratorare tried in order until one has at least one match; matches for that element are effected exhaustively and only.- Parameters:
p- the pattern to match against the elements of theIterable.- See Also:
-
anyArrayElement
Returns a pattern that matches a given pattern for any element of an array successively. Matches are effected exhaustively for each element of the array before proceeding to the next element.- Parameters:
p- the pattern to match against the elements of the array.- See Also:
-
firstArrayElement
Returns a pattern that matches a given pattern for the first matching element of an array. Elements of the array are tried in order until one has at least one match; matches for that element are effected exhaustively and only.- Parameters:
p- the pattern to match against the elements of the array.- See Also:
-
keySet
Returns a pattern that matches a given pattern against the key set of a map.- Parameters:
p- the pattern to match against the key set.- See Also:
-
values
Returns a pattern that matches a given pattern against the values of a map.- Type Parameters:
A- the type of the keys in the mapB- the type of the values in the map- Parameters:
p- the pattern to match against the values.- See Also:
-
size
Returns a pattern that matches a given pattern against the size of aCollection.- Parameters:
body- the pattern to match against the size.- See Also:
-
get
Returns a pattern that matches a given pattern against the element at a given index in aList.The failure behaviour of the resulting pattern reflects that of
List.get(int): if the given index is invalid for a target list, anIndexOutOfBoundsExceptionis thrown during matching.- Parameters:
index- the index of the element to select.body- the pattern to match against the selected element.- See Also:
-
get
Returns a pattern that matches a given pattern against the element for a given key in aMap.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 againstnull.- Parameters:
key- the key of the element to select.body- the pattern to match against the selected element.- See Also:
-
length
Returns a pattern that matches a given pattern against the length of an array.- Parameters:
body- the pattern to match against the length.
-
getArray
Returns a pattern that matches a given pattern against the element at a given index in an array.The failure behaviour of the resulting pattern reflects that of array selection: if the given index is invalid for a target array, an
ArrayIndexOutOfBoundsExceptionis thrown during matching.- Parameters:
index- the index of the element to select.body- the pattern to match against the selected element.
-
elementwise
Returns a pattern that matches a given list of patterns element-by-element against a list. The first pattern is matched against the first list element and so forth. A successful match requires the size of the target list to match the number of given patterns exactly. Multiple matches for individual patterns are combined as withPattern.all(Pattern...).- Parameters:
ps- a list of patterns to match against list elements.
-
elementwise
Returns a pattern that matches a given array of patterns element-by-element against an array. The first pattern is matched against the first array element and so forth. A successful match requires the length of the target array to match the number of given patterns exactly. Multiple matches for individual patterns are combined as withPattern.all(Pattern...).- Parameters:
ps- an array of patterns to match against array elements.
-
from
Returns a pattern that matches against elements from a given set.A pattern returned by this method is deterministic and binds no variables.
- Parameters:
set- the set of elements to match.- See Also:
-
singleton
Returns a pattern that matches a given pattern against the (single) element of a list. A successful match requires the target list to have size one exactly.- Parameters:
ps- patterns to match against the list element.
-
nil
-
cons
-
snoc
-
map
-