Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Dec 30, 2023
1 parent 3a9d930 commit 2a186ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ fun <I, O, E> Parser<I, O, E>.asList(): Parser<Collection<I>, List<O>, E> {
fun <I, O, E> Parser.Companion.list(elementParser: Parser<I, O, E>): Parser<Collection<I>, List<O>, E> =
elementParser.asList()

/**
* Wraps a [Parser] that produces lists with nullable items, to filter any null entries in the outputted list.
* In other words, transforms a Parser I -> List<O?> to I -> List<O>.
*/
fun <I, O, E> Parser<I, List<O?>, E>.filterNulls(): Parser<I, List<O>, E> = map { it.filterNotNull() }
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ fun <I, O, E> Parser<I, O, E>.asSet(): Parser<Collection<I>, Set<O>, E> {

fun <I, O, E> Parser<I, Set<O?>, E>.filterNulls(): Parser<I, Set<O>, E> = map { it.filterNotNull().toSet() }

/**
* Wraps a [Parser] that produces sets with nullable items, to filter any null entries in the outputted set.
* In other words, transforms a Parser I -> Set<O?> to I -> Set<O>.
*/
fun <I, O, E> Parser.Companion.set(elementParser: Parser<I, O, E>): Parser<Collection<I>, Set<O>, E> =
elementParser.asSet()

0 comments on commit 2a186ed

Please sign in to comment.