use Tuple2::apply instead of field access
This commit is contained in:
parent
d38a063b41
commit
c8a66fbe73
@ -87,20 +87,20 @@ public class Nouritsu extends NanoHTTPD {
|
|||||||
return getAsTuple(params, "user", "item")
|
return getAsTuple(params, "user", "item")
|
||||||
// This is where Kotlin-like destructuring would be really nice to have:
|
// This is where Kotlin-like destructuring would be really nice to have:
|
||||||
// flatMap(id, item -> ...)
|
// flatMap(id, item -> ...)
|
||||||
.flatMap(t -> dao.addToList(t._1, t._2))
|
.flatMap(t -> t.apply(dao::addToList))
|
||||||
.fold(Function.identity(), Resp.CREATED);
|
.fold(Function.identity(), Resp.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Resp addItem(Map<String, String> params, Dao dao) {
|
private static Resp addItem(Map<String, String> params, Dao dao) {
|
||||||
return getAsTuple(params, "name", "category")
|
return getAsTuple(params, "name", "category")
|
||||||
.flatMap(t -> ShoppingItem.tryParse(t._1, t._2))
|
.flatMap(t -> t.apply(ShoppingItem::tryParse))
|
||||||
.map(dao::addItem)
|
.map(dao::addItem)
|
||||||
.fold(Function.identity(), Resp.CREATED);
|
.fold(Function.identity(), Resp.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Resp addStore(Map<String, String> params, Dao dao) {
|
private static Resp addStore(Map<String, String> params, Dao dao) {
|
||||||
return getAsTuple(params, "name", "categories")
|
return getAsTuple(params, "name", "categories")
|
||||||
.flatMap(t -> Store.tryParse(t._1, t._2))
|
.flatMap(t -> t.apply(Store::tryParse))
|
||||||
.flatMap(dao::addStore)
|
.flatMap(dao::addStore)
|
||||||
.fold(Function.identity(), Resp.CREATED);
|
.fold(Function.identity(), Resp.CREATED);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user