Hi, I have a problem when I want to extract duplicate logic to a method:
this is my origin code that to perform a statistic to update the most common value from a table field :
val goods = getFromDb(goodsid)
//for cost field
from(yhGoodsShops)(gs =>
where(gs.venderid === venderid and gs.goodsid === goods.goodsid)
groupBy (gs.cost)
compute (count())
orderBy (count() desc)
).page(0, 1).toList.headOption.foreach(row => {
if (goods.cost != row.key) {
goods.cost = row.key
}
})
//for price field
from(yhGoodsShops)(gs =>
where(gs.venderid === venderid and gs.goodsid === goods.goodsid)
groupBy (gs.price)
compute (count())
orderBy (count() desc)
).page(0, 1).toList.headOption.foreach(row => {
if (goods.price != row.key) {
goods.price = row.key
}
})
I want to extract a method to do the same job like this::
goods.cost = newMethod("cost", goods.cost)
goods.price = newMethod("price", goods.price)
how I to define the newMethod ?
Thanks.