Skip to content

Implement except on Seq, Array and List#253

Closed
PatrickMcDonald wants to merge 3 commits intodotnet:fsharp4from
PatrickMcDonald:except
Closed

Implement except on Seq, Array and List#253
PatrickMcDonald wants to merge 3 commits intodotnet:fsharp4from
PatrickMcDonald:except

Conversation

@PatrickMcDonald
Copy link
Copy Markdown
Contributor

This PR addresses Add 'except' function to core collection modules

The implementation suggested in uservoice is different from the LINQ implementation as LINQ Except removes duplicates from the results. I have gone with the LINQ version for the moment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly a set difference, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not, what's the 'difference' (oooh pun)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just cogged the LINQ documentation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Then we should keep it that way. It's just a bit strange to talk about sets when we're actually in Streams or lists...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 'difference' does not necessarily imply that the result is unique elements, whereas 'set difference' [might|does]?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PatrickMcDonald
Copy link
Copy Markdown
Contributor Author

I have done some performance testing (code is in this fork)

Some results:

Iterations = 1000, n = 1000, m = 25, upper = 50

Enumerable.Except took 00:00:00.1324282
Seq.except took 00:00:00.1288203
Array.Except took 00:00:00.1381398
Seq.Except (on arrays) took 00:00:00.1309900
Enumerable.Except (on arrays) took 00:00:00.1191383
List.Except took 00:00:00.1321431
Seq.Except (on lists) took 00:00:00.1314925
Enumerable.Except (on lists) took 00:00:00.1203745

Iterations = 1000, n = 1000, m = 25, upper = 100000

Enumerable.Except took 00:00:00.1707046
Seq.except took 00:00:00.2006956
Array.Except took 00:00:00.1872810
Seq.Except (on arrays) took 00:00:00.1841139
Enumerable.Except (on arrays) took 00:00:00.1810613
List.Except took 00:00:00.1813101
Seq.Except (on lists) took 00:00:00.2028662
Enumerable.Except (on lists) took 00:00:00.1681396

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the args to make it super obvious which one is which?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with array1/array2 as that is what is used elsewhere in the module, I agree it could be more meaningful, am open to suggestions here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first/second is meaningless as well. I think that should be improved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoredItems? itemsToRemove? excludedItems?

@rojepp
Copy link
Copy Markdown
Contributor

rojepp commented Feb 20, 2015

Could you flip the argument order? I'd like to do [1;2;3;4] |> List.except [1;2].

@forki
Copy link
Copy Markdown
Contributor

forki commented Feb 20, 2015

yep that's basically why I asked: #253 (comment)

@dsyme
Copy link
Copy Markdown
Contributor

dsyme commented Feb 20, 2015

Yes, I would recommend that the arguments be flipped to allow pipelining - at least, that was my intention in suggesting that we look at implementing this. It's one reason why I prefer the name "except" to the name "difference".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update SurfaceArea.portable*.fs too

@latkin
Copy link
Copy Markdown
Contributor

latkin commented Feb 24, 2015

LGTM

@lasandell
Copy link
Copy Markdown

I guess someone can close the related uservoice issue now. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants