Skip to content

Commit

Permalink
Added javadoc on enums
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Dec 30, 2023
1 parent a4a5834 commit 7502036
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <I, E, reified ENUM : Enum<ENUM>> Parser<I, String, E>.enum(crossinline ifError: (String) -> E): Parser<I, ENUM, E> {
return flatMap { symbol ->
runCatching { enumValueOf<ENUM>(symbol) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.kotest.matchers.shouldBe
class EnumTest : FunSpec() {

enum class EnumUnderTest {
A, B, C
A
}

init {
Expand Down

0 comments on commit 7502036

Please sign in to comment.