Skip to content

Instantly share code, notes, and snippets.

@radar

radar/filters.rb Secret

Created February 14, 2018 03:45
Show Gist options
  • Save radar/99494e1afc224989f45bfd78d5db9d3f to your computer and use it in GitHub Desktop.
Save radar/99494e1afc224989f45bfd78d5db9d3f to your computer and use it in GitHub Desktop.
Filter = Struct.new(:segment_class_id, :segment_id)
f1 = Filter.new(1, 1)
f2 = Filter.new(1, 2)
f3 = Filter.new(2, 1)
# Shortest I can come up with:
# [f1, f2, f3].group_by(&:segment_class_id).map { |sc_id, segments| [sc_id, segments.map(&:segment_id)] }.to_h
# Trying to get:
# { 1 => [1, 2], 2 => [1] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment