like find, except returns the value of the block rather than the element itself.
# File lib/sup/util.rb, line 417 def argfind ret = nil find { |e| ret ||= yield(e) } ret || nil # force end
# File lib/sup/util.rb, line 423 def argmin best, bestval = nil, nil each do |e| val = yield e if bestval.nil? || val < bestval best, bestval = e, val end end best end
# File lib/sup/util.rb, line 409 def map_to_hash ret = {} each { |x| ret[x] = yield(x) } ret end
# File lib/sup/util.rb, line 401 def map_with_index ret = [] each_with_index { |x, i| ret << yield(x, i) } ret end
# File lib/sup/util.rb, line 448 def max_of map { |e| yield e }.max end
# File lib/sup/util.rb, line 407 def sum; inject(0) { |x, y| x + y }; end