// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #pragma warning disable 1591 using System.Collections.Generic; using System.Reactive.Concurrency; using System.Reactive.Linq; using System.Reactive; #if !NO_TPL using System.Reactive.Threading.Tasks; // needed for doc comments using System.Threading; using System.Threading.Tasks; #endif /* * Note: these methods just call methods in Observable.StandardSequenceOperators.cs * in order to create the following method aliases: * * Map = Select * FlatMap = SelectMany * Filter = Where * */ namespace System.Reactive.Observable.Aliases { public static class QueryLanguage { #region + Map + /// /// Projects each element of an observable sequence into a new form. Synonym for the method 'Select' /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence, obtained by running the selector function for each element in the source sequence. /// A sequence of elements to invoke a transform function on. /// A transform function to apply to each source element. /// An observable sequence whose elements are the result of invoking the transform function on each element of source. /// or is null. public static IObservable Map(this IObservable source, Func selector) { return source.Select(selector); } /// /// Projects each element of an observable sequence into a new form by incorporating the element's index. Synonym for the method 'Select' /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence, obtained by running the selector function for each element in the source sequence. /// A sequence of elements to invoke a transform function on. /// A transform function to apply to each source element; the second parameter of the function represents the index of the source element. /// An observable sequence whose elements are the result of invoking the transform function on each element of source. /// or is null. public static IObservable Map(this IObservable source, Func selector) { return source.Select(selector); } #endregion #region + FlatMap + /// /// Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the other sequence and the elements in the result sequence. /// An observable sequence of elements to project. /// An observable sequence to project each element from the source sequence onto. /// An observable sequence whose elements are the result of projecting each source element onto the other sequence and merging all the resulting sequences together. /// or is null. public static IObservable FlatMap(this IObservable source, IObservable other) { return source.SelectMany(other); } /// /// Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected inner sequences and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. /// or is null. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } /// /// Projects each element of an observable sequence to an observable sequence by incorporating the element's index and merges the resulting observable sequences into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected inner sequences and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. /// or is null. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } #if !NO_TPL /// /// Projects each element of an observable sequence to a task and merges all of the task results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the result produced by the projected tasks and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// An observable sequence whose elements are the result of the tasks executed for each element of the input sequence. /// This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . /// or is null. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } /// /// Projects each element of an observable sequence to a task by incorporating the element's index and merges all of the task results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the result produced by the projected tasks and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// An observable sequence whose elements are the result of the tasks executed for each element of the input sequence. /// This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . /// or is null. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } /// /// Projects each element of an observable sequence to a task with cancellation support and merges all of the task results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the result produced by the projected tasks and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// An observable sequence whose elements are the result of the tasks executed for each element of the input sequence. /// This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . /// or is null. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } /// /// Projects each element of an observable sequence to a task by incorporating the element's index with cancellation support and merges all of the task results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the result produced by the projected tasks and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// An observable sequence whose elements are the result of the tasks executed for each element of the input sequence. /// This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . /// or is null. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } #endif /// /// Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected intermediate sequences. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// A transform function to apply to each element of the intermediate sequence. /// An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element. /// or or is null. public static IObservable FlatMap(this IObservable source, Func> collectionSelector, Func resultSelector) { return source.SelectMany(collectionSelector, resultSelector); } /// /// Projects each element of an observable sequence to an observable sequence by incorporating the element's index, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected intermediate sequences. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element and the fourth parameter represents the index of the intermediate element. /// An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element. /// or or is null. public static IObservable FlatMap(this IObservable source, Func> collectionSelector, Func resultSelector) { return source.SelectMany(collectionSelector, resultSelector); } #if !NO_TPL /// /// Projects each element of an observable sequence to a task, invokes the result selector for the source element and the task result, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the results produced by the projected intermediate tasks. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// A transform function to apply to each element of the intermediate sequence. /// An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element. /// or or is null. /// This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . public static IObservable FlatMap(this IObservable source, Func> taskSelector, Func resultSelector) { return source.SelectMany(taskSelector, resultSelector); } /// /// Projects each element of an observable sequence to a task by incorporating the element's index, invokes the result selector for the source element and the task result, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the results produced by the projected intermediate tasks. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element. /// An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element. /// or or is null. /// This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . public static IObservable FlatMap(this IObservable source, Func> taskSelector, Func resultSelector) { return source.SelectMany(taskSelector, resultSelector); } /// /// Projects each element of an observable sequence to a task with cancellation support, invokes the result selector for the source element and the task result, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the results produced by the projected intermediate tasks. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// A transform function to apply to each element of the intermediate sequence. /// An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element. /// or or is null. /// This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . public static IObservable FlatMap(this IObservable source, Func> taskSelector, Func resultSelector) { return source.SelectMany(taskSelector, resultSelector); } /// /// Projects each element of an observable sequence to a task by incorporating the element's index with cancellation support, invokes the result selector for the source element and the task result, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the results produced by the projected intermediate tasks. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element. /// An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element. /// or or is null. /// This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using . public static IObservable FlatMap(this IObservable source, Func> taskSelector, Func resultSelector) { return source.SelectMany(taskSelector, resultSelector); } #endif /// /// Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected inner sequences and the elements in the merged result sequence. /// An observable sequence of notifications to project. /// A transform function to apply to each element. /// A transform function to apply when an error occurs in the source sequence. /// A transform function to apply when the end of the source sequence is reached. /// An observable sequence whose elements are the result of invoking the one-to-many transform function corresponding to each notification in the input sequence. /// or or or is null. public static IObservable FlatMap(this IObservable source, Func> onNext, Func> onError, Func> onCompleted) { return source.SelectMany(onNext, onError, onCompleted); } /// /// Projects each notification of an observable sequence to an observable sequence by incorporating the element's index and merges the resulting observable sequences into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected inner sequences and the elements in the merged result sequence. /// An observable sequence of notifications to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// A transform function to apply when an error occurs in the source sequence. /// A transform function to apply when the end of the source sequence is reached. /// An observable sequence whose elements are the result of invoking the one-to-many transform function corresponding to each notification in the input sequence. /// or or or is null. public static IObservable FlatMap(this IObservable source, Func> onNext, Func> onError, Func> onCompleted) { return source.SelectMany(onNext, onError, onCompleted); } /// /// Projects each element of an observable sequence to an enumerable sequence and concatenates the resulting enumerable sequences into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected inner enumerable sequences and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. /// or is null. /// The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the conversion. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } /// /// Projects each element of an observable sequence to an enumerable sequence by incorporating the element's index and concatenates the resulting enumerable sequences into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected inner enumerable sequences and the elements in the merged result sequence. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. /// or is null. /// The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the conversion. public static IObservable FlatMap(this IObservable source, Func> selector) { return source.SelectMany(selector); } /// /// Projects each element of an observable sequence to an enumerable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected intermediate enumerable sequences. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements. /// An observable sequence of elements to project. /// A transform function to apply to each element. /// A transform function to apply to each element of the intermediate sequence. /// An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element. /// or or is null. /// The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the conversion. public static IObservable FlatMap(this IObservable source, Func> collectionSelector, Func resultSelector) { return source.SelectMany(collectionSelector, resultSelector); } /// /// Projects each element of an observable sequence to an enumerable sequence by incorporating the element's index, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence. /// Synonym for the method 'SelectMany' /// /// The type of the elements in the source sequence. /// The type of the elements in the projected intermediate enumerable sequences. /// The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements. /// An observable sequence of elements to project. /// A transform function to apply to each element; the second parameter of the function represents the index of the source element. /// A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element and the fourth parameter represents the index of the intermediate element. /// An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element. /// or or is null. /// The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the conversion. public static IObservable FlatMap(this IObservable source, Func> collectionSelector, Func resultSelector) { return source.SelectMany(collectionSelector, resultSelector); } #endregion #region + Filter + /// /// Filters the elements of an observable sequence based on a predicate. /// Synonym for the method 'Where' /// /// The type of the elements in the source sequence. /// An observable sequence whose elements to filter. /// A function to test each source element for a condition. /// An observable sequence that contains elements from the input sequence that satisfy the condition. /// or is null. public static IObservable Filter(this IObservable source, Func predicate) { return source.Where(predicate); } /// /// Filters the elements of an observable sequence based on a predicate by incorporating the element's index. /// Synonym for the method 'Where' /// /// The type of the elements in the source sequence. /// An observable sequence whose elements to filter. /// A function to test each source element for a conditio; the second parameter of the function represents the index of the source element. /// An observable sequence that contains elements from the input sequence that satisfy the condition. /// or is null. public static IObservable Filter(this IObservable source, Func predicate) { return source.Where(predicate); } #endregion } } #pragma warning restore 1591