package nouritsu.types; import com.fasterxml.jackson.annotation.JsonProperty; import io.vavr.collection.List; import io.vavr.collection.Seq; import io.vavr.control.Either; /** * A store with an ordered list of sections from entrance to exit. */ public record Store( @JsonProperty("name") String name, @JsonProperty("sections") Seq
sections ) { public static Either tryParse(String name, String sections) { return Either.traverse(List.of(sections.split(",")), Section::tryParse) .mapLeft(errors -> Resp.BAD_REQUEST.apply(errors.mkString("\n") + Section.valuesAsString())) .map(secs -> new Store(name, secs)); } }