finos/morphir-elm/10.0.0

NOTE: the latest version is 22.0.2

Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.

Morphir.SDK.DataSet

This module contains functions specifically designed to work with large data sets.

type DataSet a

Represents a data set where each row is of type a.

fromList : List a -> DataSet a

Create a data set from a list.

toList : DataSet a -> List a

Turn a data set into a list.

Aggregations

( a -> key1, a -> Bool, AggregateOp a )
-> (Float -> a -> b)
-> DataSet a
-> DataSet b

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 =
        DataSet.fromList
            [ 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
            ( .key1, always True, sumOf .value )
                (\\totalValue input ->
                    ( input, totalValue / input.value )
                )
        {- ==
            DataSet.fromList
                [ ( 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 )
                ]
        -}
( a -> key1, a -> Bool, AggregateOp a )
-> ( a -> key2, a -> Bool, AggregateOp a )
-> (Float -> Float -> a -> b)
-> DataSet a
-> DataSet b

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 =
        DataSet.fromList
            [ 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
            ( .key1, always True, sumOf .value )
            ( .key2, always True, maximumOf .value )
            (\totalValue maxValue input ->
                ( input, totalValue * maxValue / input.value )
            )
        {- ==
            DataSet.fromList
                [ ( 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 )
                ]
        -}
( a -> key1, a -> Bool, AggregateOp a )
-> ( a -> key2, a -> Bool, AggregateOp a )
-> ( a -> key3, a -> Bool, AggregateOp a )
-> (Float -> Float -> Float -> a -> b)
-> DataSet a
-> DataSet b

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 =
        DataSet.fromList
            [ 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
            ( .key1, always True, sumOf .value )
            ( .key2, always True, maximumOf .value )
            ( key2 .key1 .key2, minimumOf .value )
            (\totalValue maxValue minValue input ->
                ( input, totalValue * maxValue / input.value + minValue )
            )
        {- ==
            DataSet.fromList
                [ ( 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 )
                ]
        -}

Operators

count : AggregateOp a

Count the number of rows in a group.

sumOf : (a -> Float) -> AggregateOp a

Apply a function to each row that returns a numeric value and return the sum of the values.

minimumOf : (a -> Float) -> AggregateOp a

Apply a function to each row that returns a numeric value and return the minimum of the values.

maximumOf : (a -> Float) -> AggregateOp a

Apply a function to each row that returns a numeric value and return the maximum of the values.

averageOf : (a -> Float) -> AggregateOp a

Apply a function to each row that returns a numeric value and return the average of the values.

weightedAverageOf : (a -> Float) -> (a -> Float) -> AggregateOp a

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.