# Functions that modify recipe (RecipesBase)

**URL:** <https://discourse.julialang.org/t/functions-that-modify-recipe-recipesbase/28788>\
**Category:** General Usage\
**Tags:** plots, recipe\
**Created:** [September 15, 2019, 11:20am UTC](https://discourse.julialang.org/t/functions-that-modify-recipe-recipesbase/28788 "2019-09-15T11:20:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [September 15, 2019, 11:20am UTC](https://discourse.julialang.org/t/functions-that-modify-recipe-recipesbase/28788/1 "2019-09-15T11:20:07Z")

</div>

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:

```julia
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:

```julia
@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.

```julia
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

```

```julia

```

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [September 15, 2019, 2:50pm UTC](https://discourse.julialang.org/t/functions-that-modify-recipe-recipesbase/28788/2 "2019-09-15T14:50:41Z")

</div>

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.

```julia
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.
