bodil / bodil/bodil.github.com

Mention and_then combinator

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
CSS
Stars
24
Forks
8
PR merge metrics
No merged PRs in 30d

Description

As for https://github.com/bodil/bodil.github.com/blob/master/content/parser-combinators/index.md

It would be nice to have include
```rust
fn and_then<'a, P, F, A, B, NextP>(parser: P, f: F) -> impl Parser<'a, B>
where
P: Parser<'a, A>,
NextP: Parser<'a, B>,
F: Fn(A) -> NextP,
{
move |input| parser.parse(input)
.and_then(|(next_input, result)| f(result).parse(next_input))
}
```
as an alternative to
```rust
fn and_then<'a, P, F, A, B, NextP>(parser: P, f: F) -> impl Parser<'a, B>
where
P: Parser<'a, A>,
NextP: Parser<'a, B>,
F: Fn(A) -> NextP,
{
move |input| match parser.parse(input) {
Ok((next_input, result)) => f(result).parse(next_input),
Err(err) => Err(err),
}
}
```
Maybe it might be good to mention the previous version as well.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.