use Tuple2::apply instead of field access

This commit is contained in:
kageru 2020-07-04 01:00:18 +02:00
parent d38a063b41
commit c8a66fbe73
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

@ -87,20 +87,20 @@ public class Nouritsu extends NanoHTTPD {
return getAsTuple(params, "user", "item")
// This is where Kotlin-like destructuring would be really nice to have:
// flatMap(id, item -> ...)
.flatMap(t -> dao.addToList(t._1, t._2))
.flatMap(t -> t.apply(dao::addToList))
.fold(Function.identity(), Resp.CREATED);
}
private static Resp addItem(Map<String, String> params, Dao dao) {
return getAsTuple(params, "name", "category")
.flatMap(t -> ShoppingItem.tryParse(t._1, t._2))
.flatMap(t -> t.apply(ShoppingItem::tryParse))
.map(dao::addItem)
.fold(Function.identity(), Resp.CREATED);
}
private static Resp addStore(Map<String, String> params, Dao dao) {
return getAsTuple(params, "name", "categories")
.flatMap(t -> Store.tryParse(t._1, t._2))
.flatMap(t -> t.apply(Store::tryParse))
.flatMap(dao::addStore)
.fold(Function.identity(), Resp.CREATED);
}