函数式编程

/**
*
* @param apiName
* @param requestList
* @param api
* @tparam P
* @tparam R
* @return
*/
def callApiByPage[P, R](apiName : String, requestList: List[P])(api:(List[P]) => Option[R]):Option[List[R]]={
if(requestList.nonEmpty){
try {
Some(requestList.grouped(1000).flatMap(x=> api(x)).toList)
} catch {
case e: SoaException => {
logger.error(s"调用${apiName}失败", e)
None
}
case e: Exception => {
logger.error("调用${apiName}失败", e)
None
}
} finally {
None
}
} else {
None
}
}
posted @ 2019-07-23 16:04  BarryW  阅读(277)  评论(0编辑  收藏  举报