Saxon.Api

 

 

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 Step.

 

Method Summary

 Step<TInput, TResult> At (int index)

Obtain a Step that selects the Nth item in the results of this step.

 Step<TInput, TResult> Cat (Step<TInput, TResult> other)

Obtain a Step that concatenates the results of this Step with the result of another Step applied to the same input item.

 IEnumerable<TResult> Invoke (TInput item)

Invokes this function on the given argument.

 Step<TInput, TResult> Then (Step<TResult, TResult> next)

Obtain a Step that combines the results of this step with the results of another step.

 Step<TInput, TResult> Where (Predicate<TResult> predicate)

Obtain a Step that filters the results of this Step using a supplied Predicate.

 

Constructor Detail

Step

public Step(Func<TInput, IEnumerable<TResult>> steppingFunction)

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.

Property Detail

Func

public  Func {get; }

The underlying function corresponding to this Step.

Method Detail

At

public Step<TInput, TResult> At(int index)

Obtain a Step that selects the Nth item in the results of this step.

The standard LINQ methods First() and Last() 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 selected

Returns:

A new Step (that is, a function from one IEnumerable of items to another) that filters the results of this step by selecting only the items that satisfy the predicate.

Cat

public Step<TInput, TResult> Cat(Step<TInput, TResult> other)

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 step

Returns:

A new 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

public IEnumerable<TResult> Invoke(TInput item)

Invokes this function on the given argument.

Parameters:

item - The function argument

Returns:

The function result.

Then

public Step<TInput, TResult> Then(Step<TResult, TResult> next)

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 step

Returns:

A new 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

public Step<TInput, TResult> Where(Predicate<TResult> predicate)

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:

A new 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.