@buggyorg/functional
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -62,5 +62,2 @@ 'use strict'; | ||
if (ports.length === 0) { | ||
/* if (graph.node(node).inputPorts.fn) { | ||
console.error('dead end for ', node, port, graph.node(node).inputPorts.fn.arguments) | ||
}*/ | ||
return null; | ||
@@ -104,3 +101,3 @@ } | ||
return _lodash2.default.filter(graph.nodes(), function (n) { | ||
return graph.node(n).id === 'functional/apply'; | ||
return graph.node(n).id === 'functional/call'; | ||
}); | ||
@@ -173,12 +170,14 @@ }; | ||
var type; | ||
if (p === 'function' || p === 'generic' || p === 'function|function:return' && _lodash2.default.keys(srcType.arguments).length > 1) { | ||
if (p === 'function' || p === 'generic' || p === 'function:partial') { | ||
if (p === 'generic' && apply.lambda.port !== portName) { | ||
return 'generic'; | ||
} | ||
if (p === 'function|function:return') { | ||
if (p === 'function:partial') { | ||
type = _lodash2.default.merge({}, _lodash2.default.omit(srcType, ['arguments', 'newArguments']), { arguments: srcType.newArguments }); | ||
} else if (srcType.type === 'reference' && srcType.for.node === node && srcType.for.port === portName) { | ||
type = 'generic'; | ||
} else { | ||
type = srcType; | ||
} | ||
} else if (p === 'function:return' || p === 'function|function:return') { | ||
} else if (p === 'function:return') { | ||
type = srcType.return; | ||
@@ -224,2 +223,3 @@ if (type === 'generic') { | ||
port: _lodash2.default.keys(lastType.arguments)[pNode.params.partial], | ||
portIndex: pNode.params.partial, | ||
lambda: lambda, | ||
@@ -256,3 +256,3 @@ implementation: impl, | ||
return _lodash2.default.map(applys, function (a) { | ||
if (a.type.type === 'reference') { | ||
if (a.type.type === 'reference' && _lodash2.default.has(partials, graph.parent(a.type.for.node))) { | ||
var pType = _lodash2.default.omit(partials[graph.parent(a.type.for.node)]); | ||
@@ -264,9 +264,23 @@ var type = pType.partialize.lambda; | ||
type: type, | ||
types: _lodash2.default.map(a.types, function (t) { | ||
return type; | ||
}) | ||
types: _lodash2.default.reduce(a.types, function (types, t) { | ||
var lastType = _lodash2.default.cloneDeep(types.length > 0 ? _lodash2.default.last(types) : type); | ||
if (lastType.newArguments) { | ||
lastType.arguments = lastType.newArguments; | ||
} | ||
if (!t.partialize) { | ||
return _lodash2.default.concat(types, [lastType]); | ||
} else { | ||
return types.concat(_lodash2.default.merge({}, lastType, { newArguments: _lodash2.default.omit(lastType.arguments, _lodash2.default.keys(lastType.arguments)[t.partialize.portIndex]) }, { partialize: { port: _lodash2.default.keys(lastType.arguments)[t.portIndex] } })); | ||
} | ||
}, []) | ||
}); | ||
} else { | ||
return a; | ||
} else if (a.type.type === 'reference') { | ||
var portType = _graphtools.utils.portType(graph, a.type.for.node, a.type.for.port); | ||
if (typeof portType === 'string' && portType !== 'generic') { | ||
return portType; | ||
} else { | ||
return { type: 'type-ref', node: a.type.for.node, port: a.type.for.port }; | ||
} | ||
} | ||
return a; | ||
}); | ||
@@ -336,3 +350,2 @@ } | ||
if (ppaths.length > 0) { | ||
// console.error(JSON.stringify(types, null, 2)) | ||
graph = processApplications(graph, ppaths); | ||
@@ -348,4 +361,2 @@ types = (0, _lodash2.default)(anodes).map(_lodash2.default.partial(backtrackLambda, graph)).zip(anodes).map(function (arr) { | ||
}).value(); | ||
// console.error(types[0].types[3]) | ||
// console.error(JSON.stringify(types, null, 2)) | ||
pFuns = partialFunctions(types); | ||
@@ -375,3 +386,4 @@ } | ||
inputPorts: updatePorts(n.v, n.value.inputPorts, applys[n.v]), | ||
outputPorts: updatePorts(n.v, n.value.outputPorts, applys[n.v]) | ||
outputPorts: updatePorts(n.v, n.value.outputPorts, applys[n.v]), | ||
partial: applys[n.v].types[applys[n.v].index].partialize | ||
} }); | ||
@@ -378,0 +390,0 @@ } |
{ | ||
"name": "@buggyorg/functional", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Transformation of functional concepts.", | ||
@@ -5,0 +5,0 @@ "main": "lib/api.js", |
@@ -37,5 +37,2 @@ | ||
if (ports.length === 0) { | ||
/* if (graph.node(node).inputPorts.fn) { | ||
console.error('dead end for ', node, port, graph.node(node).inputPorts.fn.arguments) | ||
}*/ | ||
return null | ||
@@ -75,3 +72,3 @@ } | ||
var applyNodes = (graph) => { | ||
return _.filter(graph.nodes(), (n) => graph.node(n).id === 'functional/apply') | ||
return _.filter(graph.nodes(), (n) => graph.node(n).id === 'functional/call') | ||
} | ||
@@ -144,12 +141,14 @@ | ||
var type | ||
if (p === 'function' || p === 'generic' || (p === 'function|function:return' && _.keys(srcType.arguments).length > 1)) { | ||
if (p === 'function' || p === 'generic' || p === 'function:partial') { | ||
if (p === 'generic' && apply.lambda.port !== portName) { | ||
return 'generic' | ||
} | ||
if (p === 'function|function:return') { | ||
if (p === 'function:partial') { | ||
type = _.merge({}, _.omit(srcType, ['arguments', 'newArguments']), {arguments: srcType.newArguments}) | ||
} else if (srcType.type === 'reference' && srcType.for.node === node && srcType.for.port === portName) { | ||
type = 'generic' | ||
} else { | ||
type = srcType | ||
} | ||
} else if (p === 'function:return' || p === 'function|function:return') { | ||
} else if (p === 'function:return') { | ||
type = srcType.return | ||
@@ -198,2 +197,3 @@ if (type === 'generic') { | ||
port: _.keys(lastType.arguments)[pNode.params.partial], | ||
portIndex: pNode.params.partial, | ||
lambda: lambda, | ||
@@ -230,3 +230,3 @@ implementation: impl, | ||
return _.map(applys, (a) => { | ||
if (a.type.type === 'reference') { | ||
if (a.type.type === 'reference' && _.has(partials, graph.parent(a.type.for.node))) { | ||
var pType = _.omit(partials[graph.parent(a.type.for.node)]) | ||
@@ -240,7 +240,26 @@ var type = pType.partialize.lambda | ||
type: type, | ||
types: _.map(a.types, (t) => type) | ||
types: _.reduce(a.types, (types, t) => { | ||
var lastType = _.cloneDeep((types.length > 0) ? _.last(types) : type) | ||
if (lastType.newArguments) { | ||
lastType.arguments = lastType.newArguments | ||
} | ||
if (!t.partialize) { | ||
return _.concat(types, [lastType]) | ||
} else { | ||
return types.concat(_.merge({}, | ||
lastType, | ||
{newArguments: _.omit(lastType.arguments, _.keys(lastType.arguments)[t.partialize.portIndex])}, | ||
{partialize: { port: _.keys(lastType.arguments)[t.portIndex] }})) | ||
} | ||
}, []) | ||
}) | ||
} else { | ||
return a | ||
} else if (a.type.type === 'reference') { | ||
var portType = utils.portType(graph, a.type.for.node, a.type.for.port) | ||
if (typeof (portType) === 'string' && portType !== 'generic') { | ||
return portType | ||
} else { | ||
return {type: 'type-ref', node: a.type.for.node, port: a.type.for.port} | ||
} | ||
} | ||
return a | ||
}) | ||
@@ -311,3 +330,2 @@ } | ||
if (ppaths.length > 0) { | ||
// console.error(JSON.stringify(types, null, 2)) | ||
graph = processApplications(graph, ppaths) | ||
@@ -322,4 +340,2 @@ types = _(anodes) | ||
.value() | ||
// console.error(types[0].types[3]) | ||
// console.error(JSON.stringify(types, null, 2)) | ||
pFuns = partialFunctions(types) | ||
@@ -345,3 +361,4 @@ } | ||
inputPorts: updatePorts(n.v, n.value.inputPorts, applys[n.v]), | ||
outputPorts: updatePorts(n.v, n.value.outputPorts, applys[n.v]) | ||
outputPorts: updatePorts(n.v, n.value.outputPorts, applys[n.v]), | ||
partial: applys[n.v].types[applys[n.v].index].partialize | ||
}}) | ||
@@ -348,0 +365,0 @@ } |
@@ -90,2 +90,3 @@ /* global describe, it */ | ||
/* | ||
it('`resolveLambdaTypes` can set functions on the path to apply', () => { | ||
@@ -95,3 +96,3 @@ var mapGraph = lambda.resolveLambdaTypes(readFixture('map.json')) | ||
expect(mapGraph.node('mapInc:upv').outputPorts.stream).to.be.an('object') | ||
}) | ||
})*/ | ||
/* | ||
@@ -98,0 +99,0 @@ it('`resolveLambdaTypes` can handle generic lambda input values', () => { |
114464
16
3199