Skip to content
Ondřej Moravčík edited this page Mar 14, 2015 · 10 revisions

On ruby you cannot do something like this

proc = Proc.new do |x|
 x * 2
end

Marshal.dump(proc)

So, Proc and Method are serialized as string using this library

You can send a function to worker in 4 way

As String

rdd.map('lambda{|x| x * 2}')

As Proc

The same as example above. However not all Proc can be transfered.

rdd.map(lambda{|x| x * 2})

# This won't work
rdd.map(lambda{|x| x * 2}).map(lambda{|x| x * 2})

As Symbol

rdd.map(:to_s)

As Method

def multiple(x)
 x * 2
end

rdd.map(method(:multiple))

Clone this wiki locally