Integrated Dynamics

Integrated Dynamics

63M Downloads

[Question] How to create unary operator from binary operator

ouroborus opened this issue ยท 3 comments

commented

We have map and reduce but I can't figure out how to use these with binary operators. What I'm trying to do is get an average of a list of integers:

in = list<int>
out = in.map(x => float(x) / in.length).reduce((x,y) => x + y)

but I can't seem to figure out what to actually plug into map to make / work this way. I tried using / as an operator in apply and then putting that and the list into map but putting that map into a display promptly crashes the server.

commented

I think my crashes are related to this (newest versions for 1.12.2). So if I put a (map (apply add 10) list) in a display it crashes the server? In that case, could you make it not crash then? :P

commented

Probably not related; please open a new issue.

commented

What you'll need is the pipe operation. You can create a float cast operator variable, pipe it's output (without materializing it) to the length of in. After that insert this newly created operator into your map operator.

Haven't tried it myself, but this should work, let me know if it doesn't.