Integrated Dynamics

Integrated Dynamics

63M Downloads

Flip operator with 3+ inputs

vitalexbel opened this issue · 5 comments

commented

Issue type:

  • ➕ Feature request

Short description:

Flip operator to flip operator with 3 inputs.
For example, reduce operator has 3 inputs (operator, list, initial value).
And I want to apply initial value and operator first, and then get an operator with only list input needed.

So I want to get this order of input values: 312

Maybe you can make an operator that can rearrange 3rd input value to to the beginning
Thanks

commented

This is definitely needed. You might call it rotate.

commented

I don't know if you had any specific plans for this, but I implemented it. Is it okay if I submit a pull request?

commented

You don't need another operator for this; it's already possible. In Pipe, put in the Reduce and Flip operators, then in Flip, put the result of the Pipe. The output will be Reduce, but with argument order "initial value", "operator", "list", as you want.

Here's a proof of how/why this works, in lambda calculus/combinatory logic notation (flip = C and pipe = (C B)):

  • flip (pipe reduce flip)
  • \x.\y.flip (pipe reduce flip) x y
  • \x.\y.pipe reduce flip y x
  • \x.\y.flip (reduce y) x
  • \x.\y.\z.flip (reduce y) x z
  • \x.\y.\z.reduce y z x
commented

I'm not able to do this with variable cards, so I'm likely misunderstanding you.
flip(pipe(flip, reduce)) is what I did. The result is List->operator->any->any.
In case I misunderstood the order, I tried flip(pipe(reduce,flip)) (this makes no sense to me, as flip takes an operator and reduce outputs type Any from whatever comes from the list). The result is List->operator->Any->operator. Though I don't know what it would do.

I'm not the OP, but I guess I am hijacking this ticket. I'm looking for a more generic way to get later inputs to the front, since my requirement is different from the OP's. I'm looking at lambda calculus to try to understand what you put there. Does "\" there mean lambda or something else?

commented

Sure, it may already be possible, but it's not trivial to do. So I'm happy with the PR on this.

Closing this as this will be available soon because of PR #636.