From 1b9106f82f13ca669f6ec13d5c5dc2389f5a3e43 Mon Sep 17 00:00:00 2001 From: sksamuel Date: Sat, 30 Dec 2023 12:07:44 -0600 Subject: [PATCH] Added parseOrNull --- .../src/main/kotlin/com/sksamuel/tribune/core/parser.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/parser.kt b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/parser.kt index 241b872..a837946 100644 --- a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/parser.kt +++ b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/parser.kt @@ -38,6 +38,11 @@ fun interface Parser { */ fun parse(input: I): EitherNel + /** + * Parses the given [input], returning a successful result, or null in the case of an error. + */ + fun parseOrNull(input: I): O? = parse(input).getOrNull() + /** * Returns a new Parser that wraps this parser, by using the supplied function [f] * to convert a given [J] into an [I].