I'm trying to convert some F# code to C# but I don't understand this particular block:
let GetItems = asyncResult {
let! items = StaticClass.getItems
return
items
|> AsyncSeq.map (fun item ->
fun handleItem -> asyncResult {
let! itemCanBeRemoved = handleItem item|> AsyncResult.mapError HandleItemError
// some code removed for clarity
})
}
My attempt to convert this is:
public static async Task<IEnumerable<T>> GetItems<T>() where T : Item
{
var items = await StaticClass.GetItems();
var tasks = new List<Task>();
foreach (var item in items)
{
bool itemCanBeRemoved;
if (itemCanBeRemoved)
{
// do something
}
else
{
// do something else
}
}
await Task.WhenAll(tasks);
return items;
}
Assuming my conversion is on the right track, I don't understand how the handleItem func is defined and then invoked within its own implementation block. Can someone please explian what handleItem is doing and how it invokes itself?