Reputation: 10482
I have four data sources that are related by a common ID (incrementing integer).
One data source P
is always available and the three others L
's may or may not be available for a given ID (i.e. ID's are not guaranteed to exist) and are received over the internet and are distinguishable by their IP address.
I gather the data sources over some interval and then I would like to join them using their ID's.
My mental model is something like this
P
in the interval P: List<'T>
L
sources: L: List<Dictionary<string, 'U>>
P
a: 'T -> int
L
source b: 'U -> int
'V = {Id: int; P: 'T; L: Dictionary<string, 'U> }
R: List<'V>
Before I run amok using hash sets and whatnot, it would be nice to get some ideas on how to do this. Maybe there are some cool F# features that makes this really easy.
Upvotes: 0
Views: 109
Reputation: 12184
I think you can translate your domain model into types in F# a bit more directly.
One data source P is always available and the three others L's may or may not be available for a given ID (i.e. ID's are not guaranteed to exist) and are received over the internet and are distinguishable by their IP address.
This describes a record type in F# pretty neatly.
type MyDataSources =
{Id: int;
P : MyDataSource;
L1: MyOtherDataSource option;
L2: MyOtherDataSource option;
L3: MyOtherDataSource option;}
I gather the data sources over some interval and then I would like to join them using their ID's.
So, we need another record type for the data.
type JoinedData<'T, 'U> =
{PData : 'T list;
L1Data : 'U list option;
L2Data : 'U list option;
L3Data : 'U list option;}
We then just need a function that takes the data sources and populates the data.
let populateDataFromSources dataSources =
{PData = getDataFrom dataSources.P // replace with whatever logic you want here
....
}
If needed, your getDataFrom
function could take the Id
from your data source as an argument and filter for data returned which relates to that Id
(for example).
Upvotes: 2