Skip to content

Commit c09efc1

Browse files
committed
👍 Improve performance of isRecordOf
The benchmark result of the previous implementation is 197.12 ns/iter but the new implementation is 88.99 ns/iter.
1 parent e46b0a1 commit c09efc1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

is.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,13 @@ export function isRecord(
138138
export function isRecordOf<T>(
139139
pred: Predicate<T>,
140140
): Predicate<RecordOf<T>> {
141-
return (x: unknown): x is RecordOf<T> =>
142-
isRecord(x) && Object.values(x).every(pred);
141+
return (x: unknown): x is RecordOf<T> => {
142+
if (!isRecord(x)) return false;
143+
for (const k in x) {
144+
if (!pred(x[k])) return false;
145+
}
146+
return true;
147+
};
143148
}
144149

145150
type FlatType<T> = T extends RecordOf<unknown>

0 commit comments

Comments
 (0)