Add some comments
This commit is contained in:
parent
ff16085c59
commit
d0dc275914
@ -44,6 +44,7 @@ public class Dao {
|
||||
return "Cleared list of user “%s“".formatted(id);
|
||||
}
|
||||
|
||||
// The .exists() check is necessary because smembers throws an exception instead of returning null or an empty set.
|
||||
private Option<HashSet<String>> getSet(String key) {
|
||||
return withRedis(redis ->
|
||||
redis.exists(key)
|
||||
|
@ -98,20 +98,20 @@ public class Nouritsu extends NanoHTTPD {
|
||||
.fold(Function.identity(), Resp.OK);
|
||||
}
|
||||
|
||||
// Return a Tuple2 containing the values of two eithers if both were Either.Right
|
||||
private static <L, R1, R2> Either<L, Tuple2<R1, R2>> zip(Either<L, R1> first, Either<L, R2> second) {
|
||||
return first.flatMap(f -> second.map(s -> Tuple.of(f, s)));
|
||||
}
|
||||
|
||||
private static String sortBySection(HashSet<ShoppingItem> items, Store store) {
|
||||
var itemsBySection = items.groupBy(ShoppingItem::section);
|
||||
var sorted = store.sections().flatMap(s -> itemsBySection.get(s).getOrElse(HashSet.empty()));
|
||||
var rest = items.removeAll(sorted);
|
||||
var sortedString = sorted.map(ShoppingItem::name).mkString(", ");
|
||||
var formattedItems = sorted.map(ShoppingItem::name).mkString(", ");
|
||||
if (rest.isEmpty()) {
|
||||
return sortedString;
|
||||
return formattedItems;
|
||||
}
|
||||
return sortedString + rest.mkString("\nItems not available or not classified in this store: ", ", ", "");
|
||||
}
|
||||
|
||||
// Return a Tuple2 containing the values of two eithers if both were Either.Right
|
||||
private static <L, R1, R2> Either<L, Tuple2<R1, R2>> zip(Either<L, R1> first, Either<L, R2> second) {
|
||||
return first.flatMap(f -> second.map(s -> Tuple.of(f, s)));
|
||||
return formattedItems + rest.mkString("\nItems not available or not classified in this store: ", ", ", "");
|
||||
}
|
||||
|
||||
private static Resp addToList(Map<String, String> params, Dao dao) {
|
||||
|
Loading…
Reference in New Issue
Block a user