Sequence

The Sequence aspect can be used to make a type implement compatibility for Sequence types and LINQ, without having to worry about the exact implementation details, which differ per platform and can involve a good deal of boilerplate code.

A single method on a class or record that is named GetSequence, takes no parameters and returns an ISequence<T> (or sequence of T in Oxygene) may be annotated with the aspect, and the compiler will automatically adjust it internally to implement the appropriate logic for each platform, and mark the type to conform to the ISequence protocol.

The GetSequence method may construct the request in any way it sees fit, and it may be an Interator.

[&Sequence]
method GetSequence: sequence of String; iterator;
begin
  for i := 0 to 10 do
    yield i.ToString();
end;
[Sequence]
public ISequence<string> GetSequence()
{
    for (int i = 0; i <= 10; i++)
        yield i.ToString();
}
@Sequence
public func GetSequence() -> ISequence<String> {
    for i in 0...10 {
        __yield i.ToString();
    }
}
@Sequence
public ISequence<String> GetSequence() {
    return { "1", "2", "3" }; // Java does not support Iterators
}

See Also