Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.
This module contains functions specifically designed to work with large data sets.
Map function that provides an aggregated value to the mapping function. The first argument is a tuple where the first element is a function that defines the aggregation key, the second element is predicate that allows you to filter out certain rows from the aggregation and the third argument is the aggregation operation to apply. Usage:
testDataSet =
[ TestInput1 "k1_1" "k2_1" 1
, TestInput1 "k1_1" "k2_1" 2
, TestInput1 "k1_1" "k2_2" 3
, TestInput1 "k1_1" "k2_2" 4
, TestInput1 "k1_2" "k2_1" 5
, TestInput1 "k1_2" "k2_1" 6
, TestInput1 "k1_2" "k2_2" 7
, TestInput1 "k1_2" "k2_2" 8
]
testDataSet
|> aggregateMap
(sumOf .value |> byKey .key1)
(\\totalValue input ->
( input, totalValue / input.value )
)
{- ==
[ ( TestInput1 "k1_1" "k2_1" 1, 10 / 1 )
, ( TestInput1 "k1_1" "k2_1" 2, 10 / 2 )
, ( TestInput1 "k1_1" "k2_2" 3, 10 / 3 )
, ( TestInput1 "k1_1" "k2_2" 4, 10 / 4 )
, ( TestInput1 "k1_2" "k2_1" 5, 26 / 5 )
, ( TestInput1 "k1_2" "k2_1" 6, 26 / 6 )
, ( TestInput1 "k1_2" "k2_2" 7, 26 / 7 )
, ( TestInput1 "k1_2" "k2_2" 8, 26 / 8 )
]
-}Map function that provides two aggregated values to the mapping function. The first argument is a tuple where the first element is a function that defines the aggregation key, the second element is predicate that allows you to filter out certain rows from the aggregation and the third argument is the aggregation operation to apply. Usage:
testDataSet =
[ TestInput1 "k1_1" "k2_1" 1
, TestInput1 "k1_1" "k2_1" 2
, TestInput1 "k1_1" "k2_2" 3
, TestInput1 "k1_1" "k2_2" 4
, TestInput1 "k1_2" "k2_1" 5
, TestInput1 "k1_2" "k2_1" 6
, TestInput1 "k1_2" "k2_2" 7
, TestInput1 "k1_2" "k2_2" 8
]
testDataSet
|> aggregateMap2
(sumOf .value |> byKey .key1)
(maximumOf .value |> byKey .key2)
(\totalValue maxValue input ->
( input, totalValue * maxValue / input.value )
)
{- ==
[ ( TestInput1 "k1_1" "k2_1" 1, 10 * 6 / 1 )
, ( TestInput1 "k1_1" "k2_1" 2, 10 * 6 / 2 )
, ( TestInput1 "k1_1" "k2_2" 3, 10 * 8 / 3 )
, ( TestInput1 "k1_1" "k2_2" 4, 10 * 8 / 4 )
, ( TestInput1 "k1_2" "k2_1" 5, 26 * 6 / 5 )
, ( TestInput1 "k1_2" "k2_1" 6, 26 * 6 / 6 )
, ( TestInput1 "k1_2" "k2_2" 7, 26 * 8 / 7 )
, ( TestInput1 "k1_2" "k2_2" 8, 26 * 8 / 8 )
]
-}Map function that provides three aggregated values to the mapping function. The first argument is a tuple where the first element is a function that defines the aggregation key, the second element is predicate that allows you to filter out certain rows from the aggregation and the third argument is the aggregation operation to apply. Usage:
testDataSet =
[ TestInput1 "k1_1" "k2_1" 1
, TestInput1 "k1_1" "k2_1" 2
, TestInput1 "k1_1" "k2_2" 3
, TestInput1 "k1_1" "k2_2" 4
, TestInput1 "k1_2" "k2_1" 5
, TestInput1 "k1_2" "k2_1" 6
, TestInput1 "k1_2" "k2_2" 7
, TestInput1 "k1_2" "k2_2" 8
]
testDataSet
|> aggregateMap3
(sumOf .value |> byKey .key1)
(maximumOf .value |> byKey .key2)
(minimumOf .value |> byKey (key2 .key1 .key2))
(\totalValue maxValue minValue input ->
( input, totalValue * maxValue / input.value + minValue )
)
{- ==
[ ( TestInput1 "k1_1" "k2_1" 1, 10 * 6 / 1 + 1 )
, ( TestInput1 "k1_1" "k2_1" 2, 10 * 6 / 2 + 1 )
, ( TestInput1 "k1_1" "k2_2" 3, 10 * 8 / 3 + 3 )
, ( TestInput1 "k1_1" "k2_2" 4, 10 * 8 / 4 + 3 )
, ( TestInput1 "k1_2" "k2_1" 5, 26 * 6 / 5 + 5 )
, ( TestInput1 "k1_2" "k2_1" 6, 26 * 6 / 6 + 5 )
, ( TestInput1 "k1_2" "k2_2" 7, 26 * 8 / 7 + 7 )
, ( TestInput1 "k1_2" "k2_2" 8, 26 * 8 / 8 + 7 )
]
-}Count the number of rows in a group.
Apply a function to each row that returns a numeric value and return the sum of the values.
Apply a function to each row that returns a numeric value and return the minimum of the values.
Apply a function to each row that returns a numeric value and return the maximum of the values.
Apply a function to each row that returns a numeric value and return the average of the values.
Apply two functions to each row that returns a numeric value and return the weighted of the values using the first function to get the weights.
Changes the key of an aggregation. Usage:
count
|> byKey .key1
== { key = .key1
, filter = always True
, operator = Count
}Adds a filter to an aggregation. Usage:
count
|> withFilter (\a -> a.value < 0)
== { key = key0
, filter = \a -> a.value < 0
, operator = Count
}
Type that represents an aggregation on a type
awith a key ofkey. It encapsulates the following information:keyis a function that gets the key of eachafilteris a function used for filtering items out before the aggregation. This can be set toalways Trueto not do any filtering.operatoris the aggregation operation to apply (count, sum, average, ...)