Function flat_map

fn flat_map<I, O, E: ParseError<I>, F, G, H>(parser: F, applied_parser: G) -> impl Parser<I, Output = O, Error = E>
where
    F: Parser<I, Error = E>,
    G: FnMut(<F as Parser<I>>::Output) -> H,
    H: Parser<I, Output = O, Error = E>

Creates a new parser from the output of the first parser, then apply that parser over the rest of the input.

# use nom::{Err,error::ErrorKind, IResult, Parser};
use nom::bytes::complete::take;
use nom::number::complete::u8;
use nom::combinator::flat_map;
# fn main() {

let mut parse = flat_map(u8, take);

assert_eq!(parse.parse(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
assert_eq!(parse.parse(&[4, 0, 1, 2][..]), Err(Err::Error((&[0, 1, 2][..], ErrorKind::Eof))));
# }