import { SYSTEM } from "@thi.ng/random/system";
import { compR } from "./compr.js";
import { __iter } from "./iterator.js";
function sample(...args) {
  const iter = __iter(sample, args);
  if (iter) {
    return iter;
  }
  const prob = args[0];
  const rnd = args[1] || SYSTEM;
  return (rfn) => {
    const r = rfn[2];
    return compR(
      rfn,
      (acc, x) => rnd.probability(prob) ? r(acc, x) : acc
    );
  };
}
export {
  sample
};
