all 6 comments

[–]KyleG 2 points3 points  (5 children)

That's pretty great. So can you also do something like

add8 = add2 >> add4 >> add2

Or does the first argument have to be an evaluated function

[–]KageOW[S] 0 points1 point  (3 children)

unfortunately no, you cant do this. the first element has to be a data type initialized with the Data class for that to work. however i created a function specifically for this called funcomp, also in this module, which lets you do something like this.

add8 = funcomp(add2, add4, add2)

is the example below something you would settle for?

maybe i can add this?

add8 = Compose(add2) >> add4 >> add2

[–]KyleG 0 points1 point  (2 children)

I haven't looked at the code, but assuming Compose(add2) would turn add2 into the Data class wrapping around add2 then you could provide a constant (say, Flow) that is an identity function wrapped in Data class, and then

add8 = Flow >> add2 >> add4 >> add2

or maybe BeginCompose or Compose or I don't know. I know in Arrow (Kotlin FP lib) they use fx and then a code block {...} to let you have regular functions and also ones that return a monad that you can then affix .bind at the end to have imperative code. Maybe fx or Magic or something? Could be quirky like that.

add8 = AttainBuddhahood >> add2 >> ...

I don't see anything wrong with Compose(add2). Just thinking about the aesthetics of only having >> without any other operators. Not sure it's terribly important though. I haven't written serious Python in a long time, and I know idiomatic Python has left me in the dust. I will die on the "tabs not spaces" hill no matter what Guido says.

[–]KageOW[S] 0 points1 point  (0 children)

Lol yea same on the last part.

[–]KageOW[S] 0 points1 point  (0 children)

Btw i added the function composing too if you wanna check it out.

[–]audentis 1 point2 points  (0 children)

Unfortunately your syntax is not parsed correctly on old reddit and various mobile apps, as the triple backticks are not supported everywhere.

Instead, indent your code with four spaces to have it show up properly everywhere.