Functions that modify recipe (RecipesBase)

I’m trying to do something seemingly simple with RecipesBase thats turning out to be a bit of a headache. Is there a pragmatic way to make a function that returns a call from an @recipe plot function?

Here is a toy prompt:

using RecipesBase
using Plots

struct PlotIt
    fn
end

(PI::PlotIt)(x) = PI.fn(x)

@recipe function piplot( Shape::PlotIt, x )
    x := x
    y := Shape.(x)
    seriestype := :path
    ()
end

struct PlotOpposite
    fn::PlotIt
end

(PO::PlotOpposite)(x) = -PO.fn(x)

So what I want to do is something like the following:

@recipe function plotopp( PO::PlotOpposite, x )
    return piplot(PlotIt( y ->  -1 * PO.fn.fn(y) ), x) #Return the result of function call to piplot
end

I know there are ways around this but I find this kind of pattern to be interesting. Figured I’d learn something making a post like this.

x = 0.0:0.1:(2pi)
PI = PlotIt( sin )
Plots.plot( PI, x )

PO = PlotOpposite( PI)
Plots.plot( PO.( x ) )#Desired outcome
Plots.plot( PO, x ) #Broken

Guess I should share the “best” way around this I’ve found so far. That is to modify the object itself and define the struct such that its flexy enough to handle both cases.

using RecipesBase
using Plots
struct PlotIt
    fn
end

(PI::PlotIt)(x) = PI.fn(x)

@recipe function piplot( Shape::PlotIt, x )
    x := x
    y := Shape.(x)
    seriestype := :path
    ()
end

function PlotOpposite(x::PlotIt)
    PlotIt( y ->  -1 * x.fn(y) ) 
end

x = 0.0:0.1:(2pi)
PI = PlotIt( sin )
Plots.plot( PI, x )

PO = PlotOpp( PI )
Plots.plot( PO, x )

Still curious if its possible to curry (think that’s the word) a recipe decorated function.