FuncPipelines

Documentation for FuncPipelines.

FuncPipelines.PipeGetType
PipeGet{name}()

A special pipeline that get the wanted names from namedtuple.

Example

julia> p = Pipeline{:x}(identity, 1) |> Pipeline{(:sinx, :cosx)}(sincos, 1) |> PipeGet{(:x, :sinx)}()
Pipelines:
  target[x] := identity(source)
  target[(sinx, cosx)] := sincos(source)
  target := (target.x, target.sinx)

julia> p(0.5)
(x = 0.5, sinx = 0.479425538604203)

julia> p = Pipeline{:x}(identity, 1) |> Pipeline{(:sinx, :cosx)}(sincos, 1) |> PipeGet{:sinx}()
Pipelines:
  target[x] := identity(source)
  target[(sinx, cosx)] := sincos(source)
  target := (target.sinx)

julia> p(0.5)
0.479425538604203
FuncPipelines.PipeVarType
PipeVar{name}(x)

A special pipeline that set x as name to the namedtuple.

Example

julia> p = Pipeline{:x}(identity, 1) |> PipeVar{:y}(5) |> Pipeline{:z}(+, (:x, :y))
Pipelines:
  target[x] := identity(source)
  target[y] := 5
  target[z] := +(target.x, target.y)

julia> p(3)
(x = 3, y = 5, z = 8)
FuncPipelines.PipelineType
Pipeline{name}(f)

Create a pipeline function with name. When calling the pipeline function, mark the result with name. f should take two arguemnt: the input and a namedtuple (can be ignored) that the result will be merged to. name can be either Symbol or tuple of Symbols.

Pipeline{name}(f, n)

Create a pipline function with name. f should take one argument, it will be applied to either the input or namedtuple depend on the value of n. n should be either 1 or 2. Equivalent to f(n == 1 ? source : target).

Pipeline{name}(f, syms)

Create a pipline function with name. syms can be either a Symbol or a tuple of Symbols. Equivalent to f(target[syms]) or f(target[syms]...) depends on the type of syms.

Example

julia> p = Pipeline{:x}(1) do x
           2x
       end
Pipeline{x}(var"#19#20"()(source))

julia> p(3)
(x = 6,)

julia> p = Pipeline{:x}() do x, y
           y.a * x
       end
Pipeline{x}(var"#21#22"()(source, target))

julia> p(2, (a=3, b=5))
(a = 3, b = 5, x = 6)

julia> p = Pipeline{:x}(y->y.a^2, 2)
Pipeline{x}(var"#23#24"()(target))

julia> p(2, (a = 3, b = 5))
(a = 3, b = 5, x = 9)

julia> p = Pipeline{(:sinx, :cosx)}(sincos, 1)
Pipeline{(sinx, cosx)}(sincos(source))

julia> p(0.5)
(sinx = 0.479425538604203, cosx = 0.8775825618903728)

julia> p = Pipeline{:z}((x, y)-> 2x+y, (:x, :y))
Pipeline{z}(var"#33#34"()(target.x, target.y))

julia> p(0, (x=3, y=5))
(x = 3, y = 5, z = 11)
FuncPipelines.PipelinesType
Pipelines(pipeline...)

Chain of Pipelines.

Example

julia> pipes = Pipelines(Pipeline{:x}((x,y)->x), Pipeline{(:sinx, :cosx)}((x,y)->sincos(x)))
Pipelines:
  target[x] := var"#25#27"()(source, target)
  target[(sinx, cosx)] := var"#26#28"()(source, target)

julia> pipes(0.3)
(x = 0.3, sinx = 0.29552020666133955, cosx = 0.955336489125606)

# or use `|>`
julia> pipes = Pipeline{:x}((x,y)->x) |> Pipeline{(:sinx, :cosx)}((x,y)->sincos(x))
Pipelines:
  target[x] := var"#29#31"()(source, target)
  target[(sinx, cosx)] := var"#30#32"()(source, target)

julia> pipes(0.3)
(x = 0.3, sinx = 0.29552020666133955, cosx = 0.955336489125606)
Base.replaceMethod
replace(f::Function, ps::Pipelines; [count::Integer])

Return a new Pipelines where each Pipeline p in ps is replaced by f(p). If count is specified, then replace at most count values in total (replacements being defined as new(x) !== x)

Base.replaceMethod
replace(f::Function, p::Pipeline)

replace the function in p with the same target name and applied arguments.

Base.setindexMethod
Base.setindex(ps::Pipelines, p::Pipeline, i::Integer)

Replace the i-th pipeline in ps with p.