Exemplo n.º 1
0
 /// <summary>Returns the total number of elements of the CloudFlow.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <param name="predicate">Optional inclusive element predicate.</param>
 /// <returns>The total number of elements.</returns>
 public static Cloud <long> Count <TSource>(this CloudFlow <TSource> flow, Func <TSource, bool> predicate = null)
 {
     if (predicate == null)
     {
         return(CloudFlowModule.length(flow));
     }
     return(flow.Where(predicate).Count());
 }
Exemplo n.º 2
0
 /// <summary>
 ///     Applies a key-generating function to each element of a CloudFlow and return a CloudFlow yielding unique keys and the result of the threading an accumulator.
 /// </summary>
 /// <typeparam name="TSource">Source flow element type.</typeparam>
 /// <typeparam name="TKey">Element key type.</typeparam>
 /// <typeparam name="TState">Accumulated state type.</typeparam>
 /// <param name="flow">Source CloudFlow.</param>
 /// <param name="projection">Key projection function.</param>
 /// <param name="folder">State updater function on the initial inputs.</param>
 /// <param name="combiner">State combiner function.</param>
 /// <param name="initializer">State initializer function.</param>
 /// <returns>A CloudFlow that has grouped accumulated states by key.</returns>
 public static CloudFlow <KeyValuePair <TKey, TState> > AggregateBy <TSource, TKey, TState>(this CloudFlow <TSource> flow, Func <TSource, TKey> projection,
                                                                                            Func <TState> initializer,
                                                                                            Func <TState, TSource, TState> folder,
                                                                                            Func <TState, TState, TState> combiner)
 {
     return(CloudFlowModule
            .foldBy(projection.ToFSharpFunc(), folder.ToFSharpFunc(), combiner.ToFSharpFunc(), initializer.ToFSharpFunc(), flow)
            .Select(tuple => new KeyValuePair <TKey, TState>(tuple.Item1, tuple.Item2)));
 }
Exemplo n.º 3
0
 /// <summary>Filters the elements of the input CloudFlow.</summary>
 /// <param name="predicate">A function to test each source element for a condition.</param>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The result CloudFlow.</returns>
 public static CloudFlow <TSource> Where <TSource>(this CloudFlow <TSource> flow, Func <TSource, bool> predicate)
 {
     return(CloudFlowModule.filter(FSharpFunc.Create(predicate), flow));
 }
Exemplo n.º 4
0
 /// <summary>Constructs a CloudFlow from a CloudVector.</summary>
 /// <param name="source">The input array.</param>
 /// <returns>The result CloudFlow.</returns>
 public static CloudFlow <TSource> AsCloudFlow <TSource>(this CloudVector <TSource> source)
 {
     return(CloudFlowModule.ofCloudVector <TSource>(source));
 }
Exemplo n.º 5
0
 /// <summary>Creates a CloudVector from the given CloudFlow.</summary>
 /// <param name="stream">The input CloudFlow.</param>
 /// <returns>The result CloudVector.</returns>
 public static Cloud <CloudVector <TSource> > ToCloudVector <TSource>(this CloudFlow <TSource> stream)
 {
     return(CloudFlowModule.toCloudVector(stream));
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Enqueues all values in the cloud flow to the supplied cloud queue
 /// </summary>
 /// <typeparam name="TSource">Cloud flow element type.</typeparam>
 /// <param name="flow">The input CloudFlow.</param>
 /// <param name="queue">Target CloudQueue to enqueue messages.</param>
 /// <returns>A Cloud computation which distributively enqueues all elements in the cloud flow to the supplied queue.</returns>
 public static Cloud <Unit> ToCloudQueue <TSource>(this CloudFlow <TSource> flow, CloudQueue <TSource> queue)
 {
     return(CloudFlowModule.toCloudQueue(queue, flow));
 }
Exemplo n.º 7
0
 /// <summary>Creates a PersistedCloudFlow from the given CloudFlow.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <param name="storageLevel">Desired storage level for the persisted CloudFlow.</param>
 /// <returns>The result PersistedCloudFlow.</returns>
 public static Cloud <PersistedCloudFlow <TSource> > Persist <TSource>(this CloudFlow <TSource> flow, StorageLevel storageLevel)
 {
     return(CloudFlowModule.persist(storageLevel, flow));
 }
Exemplo n.º 8
0
 /// <summary>
 ///     Returns true if all elements in the CloudFlow satisfy the supplied predicate.
 /// </summary>
 /// <typeparam name="TSource">Cloud flow element type.</typeparam>
 /// <param name="flow">Input cloud flow.</param>
 /// <param name="predicate">A function to test each source element for a condition.</param>
 /// <returns>Returns true if all elements in the CloudFlow satisfy the supplied predicate.</returns>
 public static Cloud <bool> All <TSource>(this CloudFlow <TSource> flow, Func <TSource, bool> predicate)
 {
     return(CloudFlowModule.forall(predicate.ToFSharpFunc(), flow));
 }
Exemplo n.º 9
0
 /// <summary>
 ///     Returns a flow that contains no duplicate elements according to their generic hash and equality comparisons.
 ///     If an element occurs multiple times in the flow then only one is retained.
 /// </summary>
 /// <typeparam name="TSource">Cloud flow element type.</typeparam>
 /// <param name="flow">Input cloud flow.</param>
 /// <returns>A CloudFlow with unique occurences of elements.</returns>
 public static CloudFlow <TSource> Distinct <TSource>(this CloudFlow <TSource> flow) where TSource : IComparable
 {
     return(CloudFlowModule.distinct(flow));
 }
Exemplo n.º 10
0
 /// <summary>Returns the sum of the elements.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The sum of the elements.</returns>
 public static Cloud <long> Sum(this CloudFlow <long> flow)
 {
     return(CloudFlowModule.sum(flow));
 }
Exemplo n.º 11
0
 /// <summary>Applies a key-generating function to each element of the input CloudFlow and yields the CloudFlow of the given length, ordered by keys.</summary>
 /// <param name="projection">A function to transform items of the input CloudFlow into comparable keys.</param>
 /// <param name="flow">The input CloudFlow.</param>
 /// <param name="takeCount">The number of elements to return.</param>
 /// <returns>The result CloudFlow.</returns>
 public static CloudFlow <TSource> OrderByDescending <TSource, TKey>(this CloudFlow <TSource> flow, Func <TSource, TKey> projection, int takeCount) where TKey : IComparable <TKey>
 {
     return(CloudFlowModule.sortByDescending(FSharpFunc.Create(projection), takeCount, flow));
 }
Exemplo n.º 12
0
 /// <summary>Applies a function to each element of the CloudFlow, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN, then this function computes f (... (f s i0)...) iN.</summary>
 /// <param name="folder">A function that updates the state with each element from the CloudFlow.</param>
 /// <param name="combiner">A function that combines partial states into a new state.</param>
 /// <param name="state">A function that produces the initial state.</param>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The final result.</returns>
 public static Cloud <TAccumulate> Aggregate <TSource, TAccumulate>(this CloudFlow <TSource> flow, Func <TAccumulate> state, Func <TAccumulate, TSource, TAccumulate> folder, Func <TAccumulate, TAccumulate, TAccumulate> combiner)
 {
     return(CloudFlowModule.fold <TAccumulate, TSource>(FSharpFunc.Create(folder), FSharpFunc.Create(combiner), FSharpFunc.Create(state), flow));
 }
Exemplo n.º 13
0
 /// <summary>
 ///     Applies a key-generating function to each element of the input flow and yields a flow of unique keys and a sequence of all elements that have each key.
 /// <remarks>
 ///     Note: This combinator may be very expensive; for example if the group sizes are expected to be large.
 ///     If you intend to perform an aggregate operation, such as sum or average,
 ///     you are advised to use CloudFlow.foldBy or CloudFlow.countBy, for much better performance.
 /// </remarks>
 /// </summary>
 /// <param name="projection">A function to transform items of the input flow into comparable keys.</param>
 /// <param name="flow">The input flow.</param>
 /// <returns>A flow of tuples where each tuple contains the unique key and a sequence of all the elements that match the key.</returns>
 public static CloudFlow <KeyValuePair <TKey, IEnumerable <TSource> > > GroupBy <TSource, TKey>(this CloudFlow <TSource> flow, Func <TSource, TKey> projection)
 {
     return(CloudFlowModule
            .groupBy(FSharpFunc.Create(projection), flow)
            .Select(tuple => new KeyValuePair <TKey, IEnumerable <TSource> >(tuple.Item1, tuple.Item2)));
 }
Exemplo n.º 14
0
 /// <summary> Returns the elements of a CloudFlow up to a specified count. </summary>
 /// <param name="n">The maximum number of items to take.</param>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The resulting CloudFlow.</returns>
 public static CloudFlow <TSource> Take <TSource>(this CloudFlow <TSource> flow, int n)
 {
     return(CloudFlowModule.take(n, flow));
 }
Exemplo n.º 15
0
 /// <summary>Transforms each element of the input CloudFlow to a new flow and flattens its elements.</summary>
 /// <param name="f">A function to transform items from the input CloudFlow.</param>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The result CloudFlow.</returns>
 public static CloudFlow <TResult> SelectMany <TSource, TResult>(this CloudFlow <TSource> flow, Func <TSource, IEnumerable <TResult> > f)
 {
     return(CloudFlowModule.collect <TSource, IEnumerable <TResult>, TResult>(FSharpFunc.Create(f), flow));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Applies a key-generating function to each element of a CloudFlow and return a CloudFlow yielding unique keys and their number of occurrences in the original sequence.
 /// </summary>
 /// <param name="projection">A function that maps items from the input CloudFlow to keys.</param>
 /// <param name="flow">The input CloudFlow.</param>
 public static CloudFlow <Tuple <TKey, long> > CountBy <TSource, TKey>(this CloudFlow <TSource> flow, Func <TSource, TKey> projection)
 {
     return(CloudFlowModule.countBy(FSharpFunc.Create(projection), flow));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Locates the minimum element of the flow by given key.
 /// </summary>
 /// <param name="projection">A function that maps items from the input CloudFlow to comparable keys.</param>
 /// <param name="flow">The input CloudFlow.</param>
 public static Cloud <TSource> MinBy <TSource, TKey>(this CloudFlow <TSource> flow, Func <TSource, TKey> projection)
 {
     return(CloudFlowModule.minBy(FSharpFunc.Create(projection), flow));
 }
Exemplo n.º 18
0
 /// <summary>Returns the sum of the elements.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The sum of the elements.</returns>
 public static Cloud <float> Sum(this CloudFlow <float> flow)
 {
     return(CloudFlowModule.sum(flow));
 }
Exemplo n.º 19
0
 /// <summary>
 ///     Returns a flow that contains no duplicate entries according to the generic hash and equality comparisons on the keys returned by the given key-generating function.
 ///     If an element occurs multiple times in the flow then only one is retained.
 /// </summary>
 /// <typeparam name="TSource">Cloud flow element type.</typeparam>
 /// <typeparam name="TKey">Distinction key type.</typeparam>
 /// <param name="flow">Input cloud flow.</param>
 /// <param name="projection">Key projection function.</param>
 /// <returns>A CloudFlow with unique occurences of elements up to key comparison.</returns>
 public static CloudFlow <TSource> DistinctBy <TSource, TKey>(this CloudFlow <TSource> flow, Func <TSource, TKey> projection) where TKey : IComparable
 {
     return(CloudFlowModule.distinctBy(projection.ToFSharpFunc(), flow));
 }
Exemplo n.º 20
0
 /// <summary>Returns the sum of the elements.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The sum of the elements.</returns>
 public static Cloud <double> Sum(this CloudFlow <double> flow)
 {
     return(CloudFlowModule.sum(flow));
 }
Exemplo n.º 21
0
 /// <summary>Creates an array from the given CloudFlow.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The result array.</returns>
 public static Cloud <TSource[]> ToArray <TSource>(this CloudFlow <TSource> flow)
 {
     return(CloudFlowModule.toArray(flow));
 }
Exemplo n.º 22
0
 /// <summary>Returns the sum of the elements.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The sum of the elements.</returns>
 public static Cloud <decimal> Sum(this CloudFlow <decimal> flow)
 {
     return(CloudFlowModule.sum(flow));
 }
Exemplo n.º 23
0
 /// <summary>Creates a PersistedCloudFlow from the given CloudFlow.</summary>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The result PersistedCloudFlow.</returns>
 public static Cloud <PersistedCloudFlow <TSource> > Cache <TSource>(this CloudFlow <TSource> flow)
 {
     return(CloudFlowModule.cache(flow));
 }
Exemplo n.º 24
0
 /// <summary>
 ///     Computes the average of a flow of numbers.
 /// </summary>
 /// <param name="flow">Input CloudFlow.</param>
 /// <returns>A cloud computation that computes the average of suplied workflow.</returns>
 public static Cloud <float> Average(this CloudFlow <float> flow)
 {
     return(CloudFlowModule.average(flow));
 }
Exemplo n.º 25
0
 /// <summary>Creates an array from the given CloudFlow.</summary>
 /// <param name="stream">The input CloudFlow.</param>
 /// <returns>The result array.</returns>
 public static Cloud <TSource[]> ToArray <TSource>(this CloudFlow <TSource> stream)
 {
     return(CloudFlowModule.toArray(stream));
 }
Exemplo n.º 26
0
 /// <summary>
 ///     Computes the average of a flow of numbers.
 /// </summary>
 /// <param name="flow">Input CloudFlow.</param>
 /// <returns>A cloud computation that computes the average of suplied workflow.</returns>
 public static Cloud <decimal> Average(this CloudFlow <decimal> flow)
 {
     return(CloudFlowModule.average(flow));
 }
Exemplo n.º 27
0
 /// <summary>Wraps array as a CloudFlow.</summary>
 /// <param name="source">The input array.</param>
 /// <returns>The result CloudFlow.</returns>
 public static CloudFlow <TSource> AsCloudFlow <TSource>(this TSource[] source)
 {
     return(CloudFlowModule.ofArray <TSource>(source));
 }
Exemplo n.º 28
0
 /// <summary>
 ///     Averages the elements of given cloud flow by applying key and value projections.
 /// </summary>
 /// <typeparam name="TSource">Source element type.</typeparam>
 /// <typeparam name="TKey">Element key type.</typeparam>
 /// <param name="flow">Input CloudFlow.</param>
 /// <param name="keyProjection">Element key projection.</param>
 /// <param name="valueProjection">Averaged value projection.</param>
 /// <returns>A flow of computed averages, distinguished by key.</returns>
 public static CloudFlow <KeyValuePair <TKey, double> > AverageByKey <TSource, TKey>(this CloudFlow <TSource> flow, Func <TSource, TKey> keyProjection, Func <TSource, double> valueProjection)
 {
     return(CloudFlowModule
            .averageByKey(keyProjection.ToFSharpFunc(), valueProjection.ToFSharpFunc(), flow)
            .Select(result => new KeyValuePair <TKey, double>(result.Item1, result.Item2)));
 }
Exemplo n.º 29
0
 /// <summary>Returns a cloud stream with a new degree of parallelism.</summary>
 /// <param name="stream">The input cloud stream.</param>
 /// <param name="degreeOfParallelism">The degree of parallelism.</param>
 /// <returns>The result cloud stream.</returns>
 public static CloudFlow <TSource> WithDegreeOfParallelism <TSource>(this CloudFlow <TSource> stream, int degreeOfParallelism)
 {
     return(CloudFlowModule.withDegreeOfParallelism(degreeOfParallelism, stream));
 }
Exemplo n.º 30
0
 /// <summary>Transforms each element of the input CloudFlow.</summary>
 /// <param name="f">A function to transform items from the input CloudFlow.</param>
 /// <param name="flow">The input CloudFlow.</param>
 /// <returns>The result CloudFlow.</returns>
 public static CloudFlow <TResult> Select <TSource, TResult>(this CloudFlow <TSource> flow, Func <TSource, TResult> f)
 {
     return(CloudFlowModule.map(FSharpFunc.Create(f), flow));
 }