noogle/queries/byType.ts

24 lines
641 B
TypeScript
Raw Normal View History

import { MetaData, NixType } from "../models/nix";
2023-01-08 18:54:23 +03:00
import { getTypes } from "./lib";
export const byType =
({ to, from }: { to: NixType; from: NixType }) =>
(data: MetaData): MetaData => {
if (to === "any" && from === "any") {
return data;
} else {
return data.filter(
// TODO: Implement proper type matching
({ name, fn_type }) => {
if (fn_type) {
const parsedType = getTypes(name, fn_type);
return (
parsedType.args.includes(from) && parsedType.types.includes(to)
);
} else {
return to === "any" && from === "any";
}
}
);
}
};