From 75020364cefe8f4e1d762d8fc6c725d0891317ac Mon Sep 17 00:00:00 2001 From: sksamuel Date: Sat, 30 Dec 2023 13:58:29 -0600 Subject: [PATCH] Added javadoc on enums --- .../src/main/kotlin/com/sksamuel/tribune/core/enums/enums.kt | 4 ++++ .../src/test/kotlin/com/sksamuel/tribune/core/enums.kt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/enums/enums.kt b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/enums/enums.kt index 04c2027..fb89104 100644 --- a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/enums/enums.kt +++ b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/enums/enums.kt @@ -5,6 +5,10 @@ import arrow.core.right import com.sksamuel.tribune.core.Parser import com.sksamuel.tribune.core.flatMap +/** + * Wraps a [Parser] that produces Strings to one that produces a value of a given enum. + * If the String is not a valid enum value, then an error is produced using [ifError]. + */ inline fun > Parser.enum(crossinline ifError: (String) -> E): Parser { return flatMap { symbol -> runCatching { enumValueOf(symbol) } diff --git a/tribune-core/src/test/kotlin/com/sksamuel/tribune/core/enums.kt b/tribune-core/src/test/kotlin/com/sksamuel/tribune/core/enums.kt index a2008f3..a77be3b 100644 --- a/tribune-core/src/test/kotlin/com/sksamuel/tribune/core/enums.kt +++ b/tribune-core/src/test/kotlin/com/sksamuel/tribune/core/enums.kt @@ -9,7 +9,7 @@ import io.kotest.matchers.shouldBe class EnumTest : FunSpec() { enum class EnumUnderTest { - A, B, C + A } init {