Help with F#: “Collection was modified”?

The problem here is that colToRemove is not an independent collection but is a projection of the collection originalCollection So changing originalCollection changes the projection which is not allowed during the iteration. The C# equivalent of the above code is the following var colToRemove = originalCollection . Where(input -> newCollection.

Any(i -> i. Id == input. Id)); foreach (var in input in colToRemove) { originalCollection.

Remove(input); } You can fix this by making colToRemove an independent collection via the List. OfSeq method let colToRemove = originalCollection |> Seq. Filter (fun input -> Seq.

Exists (fun I -> i. Id = input. Id) newCollection) originalCollection |> List.ofSeq.

The problem here is that colToRemove is not an independent collection but is a projection of the collection originalCollection. So changing originalCollection changes the projection which is not allowed during the iteration. The C# equivalent of the above code is the following var colToRemove = originalCollection .

Where(input -> newCollection. Any(i -> i. Id == input.Id)); foreach (var in input in colToRemove) { originalCollection.

Remove(input); } You can fix this by making colToRemove an independent collection via the List. OfSeq method. Let colToRemove = originalCollection |> Seq.

Filter (fun input -> Seq. Exists (fun I -> i.Id = input. Id) newCollection) originalCollection |> List.ofSeq.

I would not try to do a remove, since you are modifying a collection, but instead try to create another collection like so: let foo () = let orig = 1;2;3;4 let torem = 1;2 let find e = List. TryFind (fun i-> I = e) torem |> function | Some _-> true | None -> false List. Partition (fun e -> find e) orig //or List.

Filter (fun e-> find e) orig hth.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions