Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 58 lines (49 sloc) 1.6 KB
#!/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.