REFACTOR: simplify the base_type_of function.

This commit is contained in:
Jeremy Wall 2019-02-04 20:30:06 -06:00
parent b571ead599
commit ad7f2d22a0

View File

@ -11,13 +11,11 @@ let base_types = [
"module", "module",
]; ];
let base_type_reducer = func (acc, f) => select (acc.val is f), f, { // Computes the base type of a value.
let base_type_of = func (val) => reduce(func (acc, f) => select (acc.val is f), f, {
true = acc{typ = f}, true = acc{typ = f},
false = acc, false = acc,
}; }, {val=val, typ="null"}, base_types).typ;
// Computes the base type of a value.
let base_type_of = func (val) => reduce(base_type_reducer, {val=val, typ="null"}, base_types).typ;
// Turns any schema check module into a compile failure. // Turns any schema check module into a compile failure.
// The module must export the computed value as the result field. // The module must export the computed value as the result field.