gofront 0.0.6 → 0.0.8

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.
@@ -93,21 +93,22 @@ export const BASIC_TYPES = {
93
93
 
94
94
  export const COMPARABLE = { kind: "basic", name: "comparable" };
95
95
 
96
- export function isTypeParam(t) {
97
- return t?.kind === "typeParam";
96
+ function makeBasicPredicate(...names) {
97
+ const set = new Set(names);
98
+ const pred = (t) => {
99
+ if (!t) return false;
100
+ if (t.kind === "untyped") return set.has(t.base);
101
+ if (t.kind === "basic") return set.has(t.name);
102
+ if (t.kind === "named") return pred(t.underlying);
103
+ return false;
104
+ };
105
+ return pred;
98
106
  }
99
107
 
100
- export function isGeneric(t) {
101
- return t?.kind === "generic";
102
- }
108
+ export const isNumeric = makeBasicPredicate("int", "float64");
109
+ export const isString = makeBasicPredicate("string");
110
+ export const isBool = makeBasicPredicate("bool");
103
111
 
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;
110
- }
111
112
  export function isComplex(t) {
112
113
  if (!t) return false;
113
114
  if (t.kind === "basic" && (t.name === "complex128" || t.name === "complex64"))
@@ -119,20 +120,6 @@ export function isComplex(t) {
119
120
  export function isComplexOrNumeric(t) {
120
121
  return isNumeric(t) || isComplex(t);
121
122
  }
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
123
  export function isAny(t) {
137
124
  return t?.kind === "basic" && t.name === "any";
138
125
  }
@@ -142,13 +129,6 @@ export function isNil(t) {
142
129
  export function isVoid(t) {
143
130
  return t?.kind === "basic" && t.name === "void";
144
131
  }
145
- export function isError(t) {
146
- if (!t) return false;
147
- if (t === ERROR) return true;
148
- if (t.kind === "interface" && t.name === "error") return true;
149
- if (t.kind === "named" && isError(t.underlying)) return true;
150
- return false;
151
- }
152
132
  export function isPointer(t) {
153
133
  if (!t) return false;
154
134
  if (t.kind === "pointer") return true;