// ets_tracing: off
import * as CK from "../../../Collections/Immutable/Chunk";
import * as L from "../../../Collections/Immutable/List";
import * as Tp from "../../../Collections/Immutable/Tuple";
import { pipe } from "../../../Function";
import * as Fold from "./fold";
import * as Map from "./map";
/**
 * Accumulates incoming elements into a chunk as long as they verify predicate `p`.
 */

export function collectAllWhile(p) {
  return Map.map_(Fold.fold(Tp.tuple(L.empty(), true), Tp.get(1), ({
    tuple: [as, _]
  }, a) => {
    if (p(a)) {
      return Tp.tuple(L.prepend_(as, a), true);
    } else {
      return Tp.tuple(as, false);
    }
  }), ({
    tuple: [is, _]
  }) => CK.from(L.reverse(is)));
}
//# sourceMappingURL=collectAllWhile.js.map