<commit_before>use {Future, IntoFuture, Callback, PollResult};
use util;
use chain::Chain;

pub struct AndThen<A, B, F> {
    state: Chain<A, B, F>,
}

pub fn new<A, B, F>(future: A, f: F) -> AndThen<A, B, F>
    where A: Future,
          B: Future,
          F: Send + 'static,
{
    AndThen {
        state: Chain::new(future, f),
    }
}

fn and_then<A, B, F>(a: PollResult<A::Item, A::Error>, f: F)
                     -> PollResult<Result<B::Item, B::Future>, B::Error>
    where A: Future,
          B: IntoFuture<Error=A::Error>,
          F: FnOnce(A::Item) -> B + Send + 'static,
{
    let e = try!(a);
    util::recover(|| f(e)).map(|b| Err(b.into_future()))
}

impl<A, B, F> Future for AndThen<A, B::Future, F>
    where A: Future,
          B: IntoFuture<Error=A::Error>,
          F: FnOnce(A::Item) -> B + Send + 'static,
{
    type Item = B::Item;
    type Error = B::Error;

    fn poll(&mut self) -> Option<PollResult<B::Item, B::Error>> {
        self.state.poll(and_then::<A, B, F>)
    }

    fn cancel(&mut self) {
        self.state.cancel()
    }

    // fn await(&mut self) -> FutureResult<B::Item, B::Error> {
    //     self.state.await(and_then::<A, B, F>)
    // }

    fn schedule<G>(&mut self, g: G)
        where G: FnOnce(PollResult<B::Item, B::Error>) + Send + 'static
    {
        self.state.schedule(g, and_then::<A, B, F>)
    }

    fn schedule_boxed(&mut self, cb: Box<Callback<B::Item, B::Error>>) {
        // TODO: wut? UFCS?
        Future::schedule(self, |r| cb.call(r))
    }
}<commit_msg>Bad in main lib<commit_after>use {Future, IntoFuture, Callback, PollResult};
use util;
use chain::Chain;

pub struct AndThen<A, B, F> {
    state: Chain<A, B, F>,
}

pub fn new<A, B, F>(future: A, f: F) -> AndThen<A, B, F>
    where A: Future,
          B: Future,
          F: Send + 'static,
{
    AndThen {
        state: Chain::new(future, f),
    }
}

fn and_then<A, B, F>(a: PollResult<A::Item, A::Error>, f: F)
                     -> PollResult<Result<B::Item, B::Future>, B::Error>
    where A: Future,
          B: IntoFuture<Error=A::Error>,
          F: FnOnce(A::Item) -> B + Send + 'static,
{
    let e = try!(a);
    util::recover(|| f(e)).map(|b| Err(b.into_future()))
}

impl<A, B, F> Future for AndThen<A, B::Future, F>
    where A: Future,
          B: IntoFuture<Error=A::Error>,
          F: FnOnce(A::Item) -> B + Send + 'static,
{
    type Item = B::Item;
    type Error = B::Error;

    fn poll(&mut self) -> Option<PollResult<B::Item, B::Error>> {
        self.state.poll(and_then::<A, B, F>)
    }

    fn cancel(&mut self) {
        self.state.cancel()
    }

    // fn await(&mut self) -> FutureResult<B::Item, B::Error> {
    //     self.state.await(and_then::<A, B, F>)
    // }

    fn schedule<G>(&mut self, g: G)
        where G: FnOnce(PollResult<B::Item, B::Error>) + Send + 'static
    {
        self.state.schedule(g, and_then::<A, B, F>)
    }

    fn schedule_boxed(&mut self, cb: Box<Callback<B::Item, B::Error>>) {
        // TODO: wut? UFCS?
        self.schedule(|r| cb.call(r))
    }
}
{'fraction_non_alphanumeric': 0.1970636215334421, 'fraction_numerical': 0.0, 'mean_word_length': 2.460496613995485, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2830500', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1175, 'n_words': 280}