gofront 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -101,13 +101,22 @@ export function isGeneric(t) {
101
101
  return t?.kind === "generic";
102
102
  }
103
103
 
104
- export function isNumeric(t) {
105
- if (!t) return false;
106
- if (t.kind === "untyped") return t.base === "int" || t.base === "float64";
107
- if (t.kind === "basic") return t.name === "int" || t.name === "float64";
108
- if (t.kind === "named") return isNumeric(t.underlying);
109
- return false;
104
+ function makeBasicPredicate(...names) {
105
+ const set = new Set(names);
106
+ const pred = (t) => {
107
+ if (!t) return false;
108
+ if (t.kind === "untyped") return set.has(t.base);
109
+ if (t.kind === "basic") return set.has(t.name);
110
+ if (t.kind === "named") return pred(t.underlying);
111
+ return false;
112
+ };
113
+ return pred;
110
114
  }
115
+
116
+ export const isNumeric = makeBasicPredicate("int", "float64");
117
+ export const isString = makeBasicPredicate("string");
118
+ export const isBool = makeBasicPredicate("bool");
119
+
111
120
  export function isComplex(t) {
112
121
  if (!t) return false;
113
122
  if (t.kind === "basic" && (t.name === "complex128" || t.name === "complex64"))
@@ -119,20 +128,6 @@ export function isComplex(t) {
119
128
  export function isComplexOrNumeric(t) {
120
129
  return isNumeric(t) || isComplex(t);
121
130
  }
122
- export function isString(t) {
123
- if (!t) return false;
124
- if (t.kind === "untyped") return t.base === "string";
125
- if (t.kind === "basic") return t.name === "string";
126
- if (t.kind === "named") return isString(t.underlying);
127
- return false;
128
- }
129
- export function isBool(t) {
130
- if (!t) return false;
131
- if (t.kind === "untyped") return t.base === "bool";
132
- if (t.kind === "basic") return t.name === "bool";
133
- if (t.kind === "named") return isBool(t.underlying);
134
- return false;
135
- }
136
131
  export function isAny(t) {
137
132
  return t?.kind === "basic" && t.name === "any";
138
133
  }