package nouritsu.types; import io.vavr.collection.Stream; import io.vavr.control.Either; public enum Section { CANS, FRUITS, VEGETABLES, PASTA, RICE, MEAT, FISH, FROZEN, DAIRY, HYGIENE, BEVERAGES; public static Either tryParse(String catName) { return Stream.of(Section.values()) .find(c -> c.name().equalsIgnoreCase(catName)) .toEither("Category ā€œ%sā€ not found".formatted(catName)); } public static String valuesAsString() { return Stream.of(Section.values()) .map(Section::name) .mkString("\nValid values are: ", ", ", ""); } }