Skip to content

Commit

Permalink
refactor: external picKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Oct 26, 2023
1 parent 1c5bd5f commit f723a90
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/objectSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const PickOmitSchema = object({
omit: optional(KeysSchema),
});


function picKeys(obj: Record<string, unknown>) {
return (keys: string[]) =>
pipe(obj,
filterWithIndex((k) => keys.includes(k))
);
}

/**
* Utility to pick/omit keys from an object.
Expand All @@ -27,9 +32,7 @@ export function objectSelect(obj: Record<string, unknown>, opts: unknown): Recor
const picked = pipe(
O.fromNullable(opts.pick),
O.flatMap(NEA.fromArray),
O.map((pick) => {
return filterWithIndex((k) => pick.includes(k))(obj);
}),
O.map(picKeys(obj)),
O.getOrElse(() => obj)
);
return pipe(
Expand Down

0 comments on commit f723a90

Please sign in to comment.