Reputation: 455
I'm new to F# basically i'm attempting to use the FileHelpers library to import the csv record by record. So i can then place each object in a queue.
let importOrders (filePath:string) = do
let engine = new FileHelpers.FileHelperAsyncEngine(typeof<DataTypes.Order.OrderType>)
engine.BeginReadFile(filePath)
for o in engine do
unProccessedData.Enqueue(o)
However its saying that engine is not a type who's value can be enumerated yet it implements IEnumerable. Anyone got any suggestions on a possible fix or a different approach.
I need to be able to process the csv record by record, converting each into the orderType and then storing the order onto the queue. Thanks for the help guys
Upvotes: 2
Views: 434
Reputation: 243051
The type of engine
(which is called FileHelperAsyncEngine
) only implements the non-generic version of IEnumerable
, but it does not implement generic IEnumerable<T>
which is required by the F# compiler.
You'll need to cast the non-generic IEnumerable
to generic IEnumerable<obj>
(or to some other instantiation of the generic type, depending on what is the type of values in the collection). The following should do the trick:
let importOrders (filePath:string) =
let engine = new FileHelpers.FileHelperAsyncEngine(typeof<OrderType>)
engine.BeginReadFile(filePath)
for o in engine |> Seq.cast<obj> do // NOTE: Conversion using Seq.cast
unProccessedData.Enqueue(o)
Upvotes: 6