fable-core
Advanced tools
Comparing version 1.0.0-narumi-910 to 1.0.0-narumi-912
{ | ||
"name": "fable-core", | ||
"version": "1.0.0-narumi-910", | ||
"version": "1.0.0-narumi-912", | ||
"description": "Fable core library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -0,0 +0,0 @@ |
@@ -76,7 +76,9 @@ import { NonDeclaredType, getPropertyNames, getDefinition } from "./Util"; | ||
case "Option": | ||
return getTypeFullName(typ.generics, option) + " option"; | ||
return getTypeFullName(typ.generics[0], option) + " option"; | ||
case "Array": | ||
return getTypeFullName(typ.generics, option) + "[]"; | ||
return getTypeFullName(typ.generics[0], option) + "[]"; | ||
case "Tuple": | ||
return typ.generics.map(x => getTypeFullName(x, option)).join(" * "); | ||
case "Function": | ||
return "Func<" + typ.generics.map(x => getTypeFullName(x, option)).join(", ") + ">"; | ||
case "GenericParam": | ||
@@ -175,1 +177,13 @@ case "Interface": | ||
} | ||
export function getFunctionElements(typ) { | ||
if (typ === "function") { | ||
throw new Error("The type of the function must be known at compile time to get the elements."); | ||
} | ||
if (typ instanceof NonDeclaredType && typ.kind === "Function") { | ||
return typ.generics; | ||
} | ||
throw new Error("Type " + getTypeFullName(typ) + " is not a function type."); | ||
} | ||
export function isFunctionType(typ) { | ||
return typ === "function" || (typ instanceof NonDeclaredType && typ.kind === "Function"); | ||
} |
@@ -399,3 +399,3 @@ import { equals } from "./Util"; | ||
} | ||
export function mapFold(f, acc, xs) { | ||
export function mapFold(f, acc, xs, transform) { | ||
let result = []; | ||
@@ -411,5 +411,5 @@ let r; | ||
} | ||
return [result, acc]; | ||
return transform !== void 0 ? [transform(result), acc] : [result, acc]; | ||
} | ||
export function mapFoldBack(f, xs, acc) { | ||
export function mapFoldBack(f, xs, acc, transform) { | ||
const arr = Array.isArray(xs) || ArrayBuffer.isView(xs) ? xs : Array.from(xs); | ||
@@ -422,3 +422,3 @@ let result = []; | ||
} | ||
return [result, acc]; | ||
return transform !== void 0 ? [transform(result), acc] : [result, acc]; | ||
} | ||
@@ -425,0 +425,0 @@ export function max(xs) { |
@@ -83,5 +83,7 @@ import FableSymbol from "./Symbol"; | ||
case "Array": | ||
return typ.definition != null || needsInflate(new List(typ.generics, enclosing)); | ||
return typ.definition != null || needsInflate(new List(typ.generics[0], enclosing)); | ||
case "Tuple": | ||
return typ.generics.some((x) => needsInflate(new List(x, enclosing))); | ||
return typ.generics.some(x => needsInflate(new List(x, enclosing))); | ||
case "Function": | ||
return false; | ||
case "GenericParam": | ||
@@ -193,3 +195,3 @@ return needsInflate(resolveGeneric(typ.definition, enclosing.tail)); | ||
case "Option": | ||
return inflate(val, new List(typ.generics, enclosing), path); | ||
return inflate(val, new List(typ.generics[0], enclosing), path); | ||
case "Array": | ||
@@ -200,6 +202,8 @@ if (typ.definition != null) { | ||
else { | ||
return inflateArray(val, new List(typ.generics, enclosing), path); | ||
return inflateArray(val, new List(typ.generics[0], enclosing), path); | ||
} | ||
case "Tuple": | ||
return typ.generics.map((x, i) => inflate(val[i], new List(x, enclosing), combine(path, i))); | ||
case "Function": | ||
return val; | ||
case "GenericParam": | ||
@@ -206,0 +210,0 @@ return inflate(val, resolveGeneric(typ.definition, enclosing.tail), path); |
12
Util.js
@@ -20,3 +20,3 @@ import FSymbol from "./Symbol"; | ||
export function Option(t) { | ||
return new NonDeclaredType("Option", null, t); | ||
return new NonDeclaredType("Option", null, [t]); | ||
} | ||
@@ -31,8 +31,12 @@ function FableArray(t, isTypedArray = false) { | ||
} | ||
return new NonDeclaredType("Array", def, genArg); | ||
return new NonDeclaredType("Array", def, [genArg]); | ||
} | ||
export { FableArray as Array }; | ||
export function Tuple(ts) { | ||
return new NonDeclaredType("Tuple", null, ts); | ||
export function Tuple(types) { | ||
return new NonDeclaredType("Tuple", null, types); | ||
} | ||
function FableFunction(types) { | ||
return new NonDeclaredType("Function", null, types); | ||
} | ||
export { FableFunction as Function }; | ||
export function GenericParam(definition) { | ||
@@ -39,0 +43,0 @@ return new NonDeclaredType("GenericParam", definition); |
232544
7362