Choub890
Choub890

Reputation: 1163

Remove item from Array, with item that doesn't provide equality

How would I remove an item from an array, provided that it does not have equality?

For example, for an item with equality, I could do the following:

Array.filter (fun x -> x <> itemToRemove) array

Unfortunately, that does not work since in my case, I have a tuple in which the third item is a curried function (to which I provide the last argument later), and this does not have equality.

EDIT:

Here is the exact example I am having problems with:

let arrayWithoutReq = Array.filter (fun (req:(string * Port<'a> * ('a -> bool) option * int * DateTime)) -> req <> fullfilableReq) (originalFifoRequests.toArray())

Upvotes: 1

Views: 68

Answers (1)

Rune FS
Rune FS

Reputation: 21742

Since you are talking about identity comparison, use the build in reference comparison

let arrayWithoutReq = 
    originalFifoRequests
    |> Seq.filter (fun req -> 
           Object.ReferenceEquals(req, fullfilableReq) |> not)
    |> Seq.toArry

Upvotes: 4

Related Questions