diff --git a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/map.kt b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/map.kt index 5378d04..8e69abd 100644 --- a/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/map.kt +++ b/tribune-core/src/main/kotlin/com/sksamuel/tribune/core/map.kt @@ -36,6 +36,7 @@ fun Parser.mapIfNotNull(f: (A) -> B): Parser = * * @return a parser which returns the modified and flattened result of this parser. */ +@JvmName("deprecatedFlatMap") @Deprecated(message = "Deprecated. Use transformEither()", replaceWith = ReplaceWith("transformEither(f)")) fun Parser.flatMap(f: (A) -> EitherNel): Parser = Parser { this@flatMap.parse(it).flatMap(f) } @@ -48,6 +49,10 @@ fun Parser.flatMap(f: (A) -> EitherNel): Parser Parser.transformEither(f: (A) -> EitherNel): Parser = +fun Parser.transformEither(f: (O) -> EitherNel): Parser = Parser { this@transformEither.parse(it).flatMap(f) } +fun Parser.flatMap(f: (O) -> Parser): Parser = + Parser { i -> + parse(i).flatMap { o -> f(o).parse(i) } + }