Saxon.Api
Class Step<TInput, TResult>
-
public class Step<TInput, TResult>
A Step
represents a function from an XDM item to a sequence of items. Steps
are most commonly used as the argument to the method XdmValue.Select()
. A wide
selection of system-defined steps are available from static methods of the Saxon.Api.Steps
class. It is possible, however, to create user-defined Steps.
Constructor Summary |
|
---|---|
Step (Func<TInput, IEnumerable<TResult>> steppingFunction) Constructor method to wrap a delegate method. |
Property Summary |
|
---|---|
Func
The underlying function corresponding to this |
Method Summary |
|
---|---|
Step<TInput, TResult> | At (int index)
Obtain a |
Step<TInput, TResult> | Cat (Step<TInput, TResult> other)
Obtain a |
IEnumerable<TResult> | Invoke (TInput item) Invokes this function on the given argument. |
Step<TInput, TResult> | Then (Step<TResult, TResult> next)
Obtain a |
Step<TInput, TResult> | Where (Predicate<TResult> predicate)
Obtain a |
Constructor Detail
Step
Constructor method to wrap a delegate method.
Parameters:
steppingFunction
- Passes a delegate as a Func
with encapsulated type XdmItem
and the return value IEnumerable
of items.Method Detail
Cat
Obtain a Step
that concatenates the results of this Step
with the result of another
Step
applied to the same input item.
For example, Attribute().Cat(Child())
returns a step whose effect is
to select the attributes of a supplied element followed by its children.
Parameters:
other
- The step whose results will be concatenated with the results of this stepReturns:
Step
(that is, a function from one IEnumerable
of items to another) that
concatenates the results of applying this step to the input item, followed by the
results of applying the other step to the input item.Invoke
Invokes this function on the given argument.
Parameters:
item
- The function argumentReturns:
Then
Obtain a Step
that combines the results of this step with the results of another step.
In XPath terms, this corresponds to the "!" operator. It differs from the "/" operator in that there is no elimination of duplicates or sorting into document order.
In function programming theory this operation is often referred to as "flatMap";
in LINQ it corresponds to SelectMany
.
For example, var grandchildren = Child("*").Then(Child("*"))
constructs a step
that returns the children of the children of a node; this can be used in a statement
such as
foreach (XdmNode gc in origin.Select(grandchildren) ...
.
Parameters:
next
- The step which will be applied to the results of this stepReturns:
Step
(that is, a function from one IEnumerable
of items to another) that
performs this step and the next step in turn. The result is equivalent to the IEnumerable
method SelectMany()
function or the XPath !
operator: there is no sorting of nodes into document order, and
no elimination of duplicates.Where
Obtain a Step
that filters the results of this Step
using a supplied Predicate
.
For example, Child().Where(Predicates.IsText())
returns a Step
whose effect is to select the text node children
of a supplied element or document node. This example can be abbreviated to
Child(Predicates.IsText())
.
Similarly, Child("*").Where(n => n.NodeName.LocalName.StartsWith("h"))
selects
element children whose names begin with "h".
Parameters:
predicate
- The predicate is a function that is applied to each item in the results
of this step, and returns a boolean indicating whether that item should be included
in the result.Returns:
Step
(that is, a wrapped delegate from one Step
of items to another) that
filters the results of this step by selecting only the items that satisfy the predicate.
Obtain a
Step
that selects the Nth item in the results of this step.The standard LINQ methods
First()
andLast()
can be used on the results of a step to select the first and last items in the result.Parameters:
index
- The zero-based index of the item to be selectedReturns:
Step
(that is, a function from oneIEnumerable
of items to another) that filters the results of this step by selecting only the items that satisfy the predicate.