I’m working on a problem which I know I can solve with C#. I would like to prove to my boss that F# would be able solve in a more succinct way. However my understanding of functional programming is still fairly immature.
The Problem:
I’m working with a list of ‘Trade’ classes. The definition of the class is as follows:
type Trade(brokerId : string, productId : string, marketId : string, buySideId : string, tradeDate : string, ruleId : int) = class
member this.BrokerId = brokerId
member this.ProductId = productId
member this.MarketId = marketId
member this.BuySideId = buySideId
member this.TradeDate = tradeDate
end
I need to be able to group the trades and then apply a rule to each of the resulting groups of data.
However I cannot guarantee the grouping of the data i.e. the rule for determining the grouping will potentially change every time the program is run - so for instance I may have to group by:
- TradeDate, BrokerId
- TradeDate only
- TradeDate, BrokerId, AccountId
... and so on.
Once I have the distinct groups it would be easy (I think) to apply a rule (such as ‘is the total TradeAmount greater than 10,000’).
Any help / pointers with creating a functional orientated solution to this problem would be very welcome.
Many thanks.