From cde9fc6a8fe569203cb991121a35c2a9c7f4c420 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 22 Jan 2013 17:25:22 +0900 Subject: import 2b5dbddd740b, new directory structure in the original rx. --- .../Reactive/Linq/Observable.Blocking.cs | 503 +++++++++++++++++++++ 1 file changed, 503 insertions(+) create mode 100644 Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.Blocking.cs (limited to 'Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.Blocking.cs') diff --git a/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.Blocking.cs b/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.Blocking.cs new file mode 100644 index 0000000..1575b3d --- /dev/null +++ b/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.Blocking.cs @@ -0,0 +1,503 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +using System.Collections.Generic; + +namespace System.Reactive.Linq +{ + public static partial class Observable + { + #region + Chunkify + + + /// + /// Produces an enumerable sequence of consecutive (possibly empty) chunks of the source sequence. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The enumerable sequence that returns consecutive (possibly empty) chunks upon each iteration. + /// is null. + public static IEnumerable> Chunkify(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.Chunkify(source); + } + + #endregion + + #region + Collect + + + /// + /// Produces an enumerable sequence that returns elements collected/aggregated from the source sequence between consecutive iterations. + /// + /// The type of the elements in the source sequence. + /// The type of the elements produced by the merge operation during collection. + /// Source observable sequence. + /// Factory to create a new collector object. + /// Merges a sequence element with the current collector. + /// The enumerable sequence that returns collected/aggregated elements from the source sequence upon each iteration. + /// or or is null. + public static IEnumerable Collect(this IObservable source, Func newCollector, Func merge) + { + if (source == null) + throw new ArgumentNullException("source"); + if (newCollector == null) + throw new ArgumentNullException("newCollector"); + if (merge == null) + throw new ArgumentNullException("merge"); + + return s_impl.Collect(source, newCollector, merge); + } + + /// + /// Produces an enumerable sequence that returns elements collected/aggregated from the source sequence between consecutive iterations. + /// + /// The type of the elements in the source sequence. + /// The type of the elements produced by the merge operation during collection. + /// Source observable sequence. + /// Factory to create the initial collector object. + /// Merges a sequence element with the current collector. + /// Factory to replace the current collector by a new collector. + /// The enumerable sequence that returns collected/aggregated elements from the source sequence upon each iteration. + /// or or or is null. + public static IEnumerable Collect(this IObservable source, Func getInitialCollector, Func merge, Func getNewCollector) + { + if (source == null) + throw new ArgumentNullException("source"); + if (getInitialCollector == null) + throw new ArgumentNullException("getInitialCollector"); + if (merge == null) + throw new ArgumentNullException("merge"); + if (getNewCollector == null) + throw new ArgumentNullException("getNewCollector"); + + return s_impl.Collect(source, getInitialCollector, merge, getNewCollector); + } + + #endregion + + #region First + + /// + /// Returns the first element of an observable sequence. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The first element in the observable sequence. + /// is null. + /// The source sequence is empty. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource First(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.First(source); + } + + /// + /// Returns the first element of an observable sequence that satisfies the condition in the predicate. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// A predicate function to evaluate for elements in the source sequence. + /// The first element in the observable sequence that satisfies the condition in the predicate. + /// or is null. + /// No element satisfies the condition in the predicate. -or- The source sequence is empty. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource First(this IObservable source, Func predicate) + { + if (source == null) + throw new ArgumentNullException("source"); + if (predicate == null) + throw new ArgumentNullException("predicate"); + + return s_impl.First(source, predicate); + } + + #endregion + + #region FirstOrDefault + + /// + /// Returns the first element of an observable sequence, or a default value if no such element exists. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The first element in the observable sequence, or a default value if no such element exists. + /// is null. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource FirstOrDefault(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.FirstOrDefault(source); + } + + /// + /// Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// A predicate function to evaluate for elements in the source sequence. + /// The first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists. + /// or is null. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource FirstOrDefault(this IObservable source, Func predicate) + { + if (source == null) + throw new ArgumentNullException("source"); + if (predicate == null) + throw new ArgumentNullException("predicate"); + + return s_impl.FirstOrDefault(source, predicate); + } + + #endregion + + #region + ForEach + + + /// + /// Invokes an action for each element in the observable sequence, and blocks until the sequence is terminated. + /// + /// The type of the elements in the source sequence. + /// Source sequence. + /// Action to invoke for each element in the observable sequence. + /// or is null. + /// Because of its blocking nature, this operator is mainly used for testing. +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static void ForEach(this IObservable source, Action onNext) + { + if (source == null) + throw new ArgumentNullException("source"); + if (onNext == null) + throw new ArgumentNullException("onNext"); + + s_impl.ForEach(source, onNext); + } + + /// + /// Invokes an action for each element in the observable sequence, incorporating the element's index, and blocks until the sequence is terminated. + /// + /// The type of the elements in the source sequence. + /// Source sequence. + /// Action to invoke for each element in the observable sequence. + /// or is null. + /// Because of its blocking nature, this operator is mainly used for testing. +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static void ForEach(this IObservable source, Action onNext) + { + if (source == null) + throw new ArgumentNullException("source"); + if (onNext == null) + throw new ArgumentNullException("onNext"); + + s_impl.ForEach(source, onNext); + } + + #endregion + + #region + GetEnumerator + + + /// + /// Returns an enumerator that enumerates all values of the observable sequence. + /// + /// The type of the elements in the source sequence. + /// An observable sequence to get an enumerator for. + /// The enumerator that can be used to enumerate over the elements in the observable sequence. + /// is null. + public static IEnumerator GetEnumerator(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.GetEnumerator(source); + } + + #endregion + + #region Last + + /// + /// Returns the last element of an observable sequence. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The last element in the observable sequence. + /// is null. + /// The source sequence is empty. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource Last(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.Last(source); + } + + /// + /// Returns the last element of an observable sequence that satisfies the condition in the predicate. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// A predicate function to evaluate for elements in the source sequence. + /// The last element in the observable sequence that satisfies the condition in the predicate. + /// or is null. + /// No element satisfies the condition in the predicate. -or- The source sequence is empty. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource Last(this IObservable source, Func predicate) + { + if (source == null) + throw new ArgumentNullException("source"); + if (predicate == null) + throw new ArgumentNullException("predicate"); + + return s_impl.Last(source, predicate); + } + + #endregion + + #region LastOrDefault + + /// + /// Returns the last element of an observable sequence, or a default value if no such element exists. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The last element in the observable sequence, or a default value if no such element exists. + /// is null. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource LastOrDefault(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.LastOrDefault(source); + } + + /// + /// Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// A predicate function to evaluate for elements in the source sequence. + /// The last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists. + /// or is null. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource LastOrDefault(this IObservable source, Func predicate) + { + if (source == null) + throw new ArgumentNullException("source"); + if (predicate == null) + throw new ArgumentNullException("predicate"); + + return s_impl.LastOrDefault(source, predicate); + } + + #endregion + + #region + Latest + + + /// + /// Returns an enumerable sequence whose enumeration returns the latest observed element in the source observable sequence. + /// Enumerators on the resulting sequence will never produce the same element repeatedly, and will block until the next element becomes available. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The enumerable sequence that returns the last sampled element upon each iteration and subsequently blocks until the next element in the observable source sequence becomes available. + public static IEnumerable Latest(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.Latest(source); + } + + #endregion + + #region + MostRecent + + + /// + /// Returns an enumerable sequence whose enumeration returns the most recently observed element in the source observable sequence, using the specified initial value in case no element has been sampled yet. + /// Enumerators on the resulting sequence never block and can produce the same element repeatedly. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// Initial value that will be yielded by the enumerable sequence if no element has been sampled yet. + /// The enumerable sequence that returns the last sampled element upon each iteration. + /// is null. + public static IEnumerable MostRecent(this IObservable source, TSource initialValue) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.MostRecent(source, initialValue); + } + + #endregion + + #region + Next + + + /// + /// Returns an enumerable sequence whose enumeration blocks until the next element in the source observable sequence becomes available. + /// Enumerators on the resulting sequence will block until the next element becomes available. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The enumerable sequence that blocks upon each iteration until the next element in the observable source sequence becomes available. + /// is null. + public static IEnumerable Next(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.Next(source); + } + + #endregion + + #region Single + + /// + /// Returns the only element of an observable sequence, and throws an exception if there is not exactly one element in the observable sequence. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The single element in the observable sequence. + /// is null. + /// The source sequence contains more than one element. -or- The source sequence is empty. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource Single(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.Single(source); + } + + /// + /// Returns the only element of an observable sequence that satisfies the condition in the predicate, and throws an exception if there is not exactly one element matching the predicate in the observable sequence. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// A predicate function to evaluate for elements in the source sequence. + /// The single element in the observable sequence that satisfies the condition in the predicate. + /// or is null. + /// No element satisfies the condition in the predicate. -or- More than one element satisfies the condition in the predicate. -or- The source sequence is empty. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource Single(this IObservable source, Func predicate) + { + if (source == null) + throw new ArgumentNullException("source"); + if (predicate == null) + throw new ArgumentNullException("predicate"); + + return s_impl.Single(source, predicate); + } + + #endregion + + #region SingleOrDefault + + /// + /// Returns the only element of an observable sequence, or a default value if the observable sequence is empty; this method throws an exception if there is more than one element in the observable sequence. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The single element in the observable sequence, or a default value if no such element exists. + /// is null. + /// The source sequence contains more than one element. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource SingleOrDefault(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.SingleOrDefault(source); + } + + /// + /// Returns the only element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists; this method throws an exception if there is more than one element matching the predicate in the observable sequence. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// A predicate function to evaluate for elements in the source sequence. + /// The single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists. + /// or is null. + /// The sequence contains more than one element that satisfies the condition in the predicate. + /// +#if PREFER_ASYNC + [Obsolete(Constants_Linq.USE_ASYNC)] +#endif + public static TSource SingleOrDefault(this IObservable source, Func predicate) + { + if (source == null) + throw new ArgumentNullException("source"); + if (predicate == null) + throw new ArgumentNullException("predicate"); + + return s_impl.SingleOrDefault(source, predicate); + } + + #endregion + + #region Wait + + /// + /// Waits for the observable sequence to complete and returns the last element of the sequence. + /// If the sequence terminates with an OnError notification, the exception is throw. + /// + /// The type of the elements in the source sequence. + /// Source observable sequence. + /// The last element in the observable sequence. + /// is null. + /// The source sequence is empty. + public static TSource Wait(this IObservable source) + { + if (source == null) + throw new ArgumentNullException("source"); + + return s_impl.Wait(source); + } + + #endregion + } +} -- cgit v1.2.3