That is fine. The approach that @mcabbott roposed there (the functor) may the best one, then. Anyway, this is what it could look like:

```
using Parameters
@with_kw mutable struct IIRfilter
@assert 0 <= alpha <= 1 "alpha must be between 0 and 1"
state::Union{Float64,Nothing} = nothing
alpha::Float64
end
# Apply to a single number
function (f::IIRfilter)(x::Number)
if f.state == nothing
f.state = x
else
f.state = f.alpha*f.state + (1-f.alpha)*x
end
return f.state
end
# Apply filter to a vector
function (f::IIRfilter)(x::AbstractVector)
xf = similar(x)
for i in eachindex(x)
xf[i] = f(x[i]) # this calls the definition above
end
return xf
end
# set data
n = 3000
xv = rand(n)
# set filter
filter = IIRfilter(alpha=0.9)
# Use on a vector
xf = filter(xv)
# Use on a single data point
x = filter(1.0)
```