Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 57 lines (49 sloc) 1.642 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!/usr/bin/env ruby

$indent = " "

def make_tuple_conv(cnt)
  type_names = ('A'..'Z').to_a[0...cnt]
  indices = (0...cnt).to_a
  comma_tn = type_names.join(",")
  getters = type_names.map { |n|
              #" g#{n} : TupleGetter[#{n}]"
              " g#{n} : TupleGetter[#{n}]"
            }.join(",\n#{$indent}")
  typed_args = type_names.zip(indices).map { |n,ni|
                 "g#{n}.get(tup, #{ni})"
               }.join(",\n#{$indent} ")
  %Q|\n#{$indent}implicit def tuple#{cnt}Converter[#{comma_tn}](implicit
#{$indent}#{getters}) = new TupleConverter[Tuple#{cnt}[#{comma_tn}]]{
#{$indent} def apply(te : TupleEntry) = {
#{$indent} val tup = te.getTuple
#{$indent} Tuple#{cnt}(#{typed_args})
#{$indent} }
#{$indent} def arity = #{cnt}
#{$indent}}
|
end

def make_setter(cnt)
  underscores = (["_"]*cnt).join(",")
  head = %Q|\n#{$indent}implicit object Tup#{cnt}Setter extends TupleSetter[Tuple#{cnt}[#{underscores}]] {
#{$indent} override def apply(arg : Tuple#{cnt}[#{underscores}]) = {
#{$indent} val tup = new Tuple
#{$indent} |
  middle = (1..cnt).map {|c| "tup.add(arg._#{c})" }.join("\n#{$indent} ")
  tail = %Q|
#{$indent} tup
#{$indent} }

#{$indent} override def arity = #{cnt}
#{$indent}}|
  head + middle + tail
end

puts "// following were autogenerated by #{__FILE__} at #{Time.now} do not edit"
puts %q|package com.twitter.scalding
import cascading.tuple.Tuple
import cascading.tuple.TupleEntry

trait GeneratedConversions extends LowPriorityConversions {
|

(1..22).each { |c|
  puts make_tuple_conv(c)
  puts make_setter(c)
}

puts "}"
puts "// end of autogenerated"
Something went wrong with that request. Please try again.