def divideset(rows, column, value)
split_function = nil
if value.is_a?(Fixnum) || value.is_a?(Float)
split_function = lambda{|row| row[column] >= value}
else
split_function = lambda{|row| row[column] == value}
end
set1 = rows.select{|row| split_function.call(row)}
set2 = rows.reject{|row| split_function.call(row)}
[set1, set2]
end
In this code from treepredict, why use lambdas?
It seems that instead of calling split_function.call(row)
, the author could have predefined two different methods to handle the two conditions of the if/else statement -- one for the case where row[column] >= value
and the other for the case where row[column] == value
Is there any additional advantage here from using the lambda?