From: daniel@...42.com Date: 2019-09-11T14:10:47+00:00 Subject: [ruby-core:94901] [Ruby master Feature#16146] Array .difference allow custom comparison Issue #16146 has been updated by Dan0042 (Daniel DeLorme). What you're asking for is a O(n�) operation. I'm not sure it's a good idea to make that so easy and transparent as a core method. This is quite easy to code and makes the (inefficiency of) two loops more apparent: ```ruby all.reject{ |a| set.find{ |s| s.val == a.val } } ``` The one advantage I can see to the <=> comparator tough is that it could possibly result in an algorithm more efficient than O(n�). The implementation could sort the two lists and then do a diff-like operation. ```ruby only_all,intersection,only_subset = all.uniqdiff3(subset){ |a,b| a.val <=> b.val } union = only_all + intersection + only_subset ``` ---------------------------------------- Feature #16146: Array .difference allow custom comparison https://bugs.ruby-lang.org/issues/16146#change-81515 * Author: ngomez (Nancy Gomez) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Hello! I wanted to know if there's any plan to implement the ability to define comparison between individual items in arrays. Here is where I originally asked the question on Stack Overflow: https://stackoverflow.com/questions/57316775/is-there-any-way-to-specify-how-to-compare-of-array-of-objects-for-difference-f But specifically, I noticed nearly all the existing Array functions allow us to define ways for comparison, such as #uniq but #difference does not :( This is quite unfortunate but I'm hoping it's just because this function was introduced in 2.6.0, and hopefully this feature can be implemented? Thanks for any and all info :) -- https://bugs.ruby-lang.org/ Unsubscribe: