Skip to content

FP-TS partition

Partition a collection using fp-ts
TypeScript
Partition.ts
import * as Array from 'fp-ts/Array';
import * as Separated from 'fp-ts/Separated';
import { pipe } from 'fp-ts/function';
 
type User = {
  name: string;
  isActive: boolean;
};
 
const users = [
  { name: 'Alice', isActive: true },
  { name: 'Bob', isActive: true },
  { name: 'Charlie', isActive: false },
];
 
function userIsActive(user: User) {
  return user.isActive;
}
 
const deactivatedUsers = pipe(
  users,
  Array.partition(userIsActive),
  Separated.left
); // [{name: 'Charlie', isActive: false}]