这是我的android应用
suspend fun getTraidersList(isCustomtHandle: Boolean = false): Any {
if (isCustomtHandle) {
return runOperationWithoutHandle {
traderMonitorRestClient.getTraidersList()
}
} else {
return runOperationWithDefaultHandle {
traderMonitorRestClient.getTraidersList()
}
}
}
suspend fun executeTraderOperation(traderOperation: Trader.Operation, base: String, quote: String, isCustomtHandle: Boolean = false): Any {
val sender = BuildConfig.APPLICATION_ID + "_" + BuildConfig.VERSION_NAME
val key = DateUtil.getDateAsString(Date(), "mmHHddMMyyyy")
if (isCustomtHandle) {
return runOperationWithoutHandle {
traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key)
}
} else {
return runOperationWithDefaultHandle {
traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key)
}
}
}
suspend private fun runOperationWithoutHandle(func: suspend () -> Response<*>): Response<*> = withContext(Dispatchers.IO) {
val response: Response<*> = func() // in runtime replace by method body (e.g. traderMonitorRestClient.getTraidersList())
response
}
suspend private fun runOperationWithDefaultHandle(func: suspend () -> Response<*>): TransportResponse = withContext(Dispatchers.IO) {
try {
val response: Response<*> = func() // in runtime replace by method body (e.g. traderMonitorRestClient.getTraidersList())
if (response.isSuccessful) { // status (200-299)
onSuccess(response)
} else {// error - status (300-599)
val errorResponse: ErrorResponse = ErrorUtils.parseError(response)
onError(errorResponse)
}
} catch (e: Throwable) {
val errorResponse = ErrorResponse()
errorResponse.setCode(SERVICE_UNAVAILABLE_CODE)
errorResponse.message = MyApplication.getAppContext().getString(R.string.service_unavailable)
onError(errorResponse)
}
}
当isCustomtHandle
为 true 时,将lambda称为“ runOperationWithoutHandle
”。此lambda 仅执行http请求而不处理。
当isCustomtHandle
为 false 时,将lambda称为“ runOperationWithDefaultHandle
”。此lambda执行http请求和处理响应。
好。这项工作正常。
但是正如您所见,在线上有重复
traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key)
和
行
traderMonitorRestClient.getTraidersList()
如何删除此重复项?我想打线
traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key)
和
traderMonitorRestClient.getTraidersList()
仅一次。
我该怎么做?
答案 0 :(得分:1)
您可以在ws = wb['sheet1'] # why people persist in using long deprecated syntax is beyond me
flag = None
for row in ws.iter_rows(max_row=10508, min_col=6, max_col=6):
cell = row[0]
sign = cell.value > 0 and "positive" or "negative"
if flag is not None and sign != flag:
print(cell.row)
flag = sign
函数内部本地添加一个匿名挂起函数,并从executeTraderOperation
语句的两个分支中调用该函数吗?例如
if