Previous UML Classes Table of Contents UML Packages Next


11.3.40 ReduceAction

CompleteActions


   (CompleteActions ) ReduceAction is an action that reduces a collection to a single value by combining the elements of the collection.

*Generalizations

   

    Action (from BasicActions ) on page 247

*Description

   This action takes a collection as input and produces an output by applying a behavior with two inputs pairwise to the elements of the collection.

*Attributes

   • isOrdered : Boolean = false Tells whether the order of the input collection should determine the order in which the behavior is applied to its elements.

*Associations

*Constraints

   [1] The type of the input must be a collection.

   [2] The type of the output must be compatible with the type of the output of the reducer behavior.

   [3] The reducer behavior must have two input parameters and one output parameter, of types compatible with the types of elements of the input collection.

*Semantics

   The behavior is invoked repeatedly on pairs of elements in the input collection. Each time it is invoked, it produces one output that is put back in an intermediate version of the collection. This repeats until the collection is reduced to a single value, which is the output of the action.

   If isOrdered is false, the order in which the behavior is applied to pairs of values is indeterminate. This will not affect the result of the action if the behavior is commutative and associative, see below. If separate invocations of the behavior affect each other, for example, through side-effects, the result of the actions may be unpredictable, however. If the reducing behavior is not commutative and associative, as with matrix multiplication, the order of the elements in the collection will affect the result of the behavior and the action. In this case, isOrdered should be set to true, so the behavior will be applied to adjacent pairs according to the collection order. The result of each invocation of the behavior replaces the two values taken as input in the same position in the order as the two values. If isOrdered = false, the reducer behavior should be commutative and associative so it will produce the same reduced value regardless of which two elements are paired at each invocation. For example, addition is commutative because because a + b = b + a. It is also associative because ((a + b) + c) = (a + (b + c)). Commutativity and associativity are not required, but the result will be indeterminate if isOrdered = false.

*Notation

   None.

*Examples

   ReduceAction can be used to reduce a list of numbers to the sum of the numbers. It would have one input pin for a collection of numbers, one result pin for a number, and an addition function as the reducer behavior. For example, suppose the input collection has four integers: (2, 7, 5, -3). The result of applying the reduce action to this collection with an addition function is 11. This can be computed in a number of ways, for example, ( ( (2+7) + 5) + -3), (2 + (7 + (5 + 3))), ((2 + 7) + (5 + -3)).

   The purpose of ReduceAction is to specify the transformation of a collection to a single value by pairwise application of a behavior, without necessarily committing to the order in which the pairs are chosen.

*Changes from previous UML

   ReduceAction replaces ReduceAction in UML 1.5. It has the same functionality, except it takes one collection instead of multiple as input, and produces one result instead of multiple. The effect of multiple input collections can be achieved in UML 2 with an input that is a collection of collections, where the nested collections are created by taking one element from each of the multiple collection inputs to the UML 1.5 ReduceAction .