import {
  compact,
  separate
} from "./chunk-47WJXJHK.mjs";
import {
  getLeft,
  getRight
} from "./chunk-3AL4EMTU.mjs";
import {
  not
} from "./chunk-RE4IFSW6.mjs";
import {
  separated
} from "./chunk-RAKKSTP2.mjs";
import {
  getFunctorComposition
} from "./chunk-WKK6AYQI.mjs";
import {
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/Filterable.ts
var Filterable_exports = {};
__export(Filterable_exports, {
  filter: () => filter,
  filterMap: () => filterMap,
  getFilterableComposition: () => getFilterableComposition,
  partition: () => partition,
  partitionMap: () => partitionMap
});
function filter(F, G) {
  return (predicate) => (fga) => F.map(fga, (ga) => G.filter(ga, predicate));
}
function filterMap(F, G) {
  return (f) => (fga) => F.map(fga, (ga) => G.filterMap(ga, f));
}
function partition(F, G) {
  const _filter = filter(F, G);
  return (predicate) => {
    const left = _filter(not(predicate));
    const right = _filter(predicate);
    return (fgb) => separated(left(fgb), right(fgb));
  };
}
function partitionMap(F, G) {
  const _filterMap = filterMap(F, G);
  return (f) => (fga) => separated(
    pipe(
      fga,
      _filterMap((a) => getLeft(f(a)))
    ),
    pipe(
      fga,
      _filterMap((a) => getRight(f(a)))
    )
  );
}
function getFilterableComposition(F, G) {
  const map = getFunctorComposition(F, G).map;
  const _compact = compact(F, G);
  const _separate = separate(F, G, G);
  const _filter = filter(F, G);
  const _filterMap = filterMap(F, G);
  const _partition = partition(F, G);
  const _partitionMap = partitionMap(F, G);
  return {
    map,
    compact: _compact,
    separate: _separate,
    filter: (fga, f) => pipe(fga, _filter(f)),
    filterMap: (fga, f) => pipe(fga, _filterMap(f)),
    partition: (fga, p) => pipe(fga, _partition(p)),
    partitionMap: (fga, f) => pipe(fga, _partitionMap(f))
  };
}

export {
  filter,
  filterMap,
  partition,
  partitionMap,
  getFilterableComposition,
  Filterable_exports
};
