Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /usr/bin/env ruby
$deps = {
:network => [ :foo, :bar, :baz],
:foo => [:testsuite, :yast2],
:bar => [:yast2, :testsuite],
:baz => [:yast2, :testsuite],
:yast2 => [:testsuite],
:testsuite => []
}
class Array
# For debugging, let's "mute" uniq.
# I cannot think of a reasonable implementation that would keep
# other element than the first occurring.
def evil_uniq
# uniq
dup
end
end
def transitive_deps0(target)
deps_of_deps = $deps[target].map { |d| transitive_deps0(d) }
(deps_of_deps.reduce([], :+) + $deps[target]).evil_uniq
end
def transitive_deps1(target)
deps_of_deps = $deps[target].map { |d| transitive_deps1(d) }
deps_of_deps.reduce($deps[target], :+).evil_uniq
end
puts "original"
p transitive_deps0(:network)
puts "reduced"
p transitive_deps1(:network)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.