diff --git a/src/RecursiveApply/RecursiveApply.jl b/src/RecursiveApply/RecursiveApply.jl old mode 100644 new mode 100755 index e4127d0a7b..756b31e3a8 --- a/src/RecursiveApply/RecursiveApply.jl +++ b/src/RecursiveApply/RecursiveApply.jl @@ -14,26 +14,29 @@ export ⊞, ⊠, ⊟ Recursively apply `fn` to each element of `X` """ -rmap(fn, X) = fn(X) -rmap(fn, X, Y) = fn(X, Y) -rmap(fn, X::Tuple) = map(x -> rmap(fn, x), X) -rmap(fn, X::Tuple, Y::Tuple) = map((x, y) -> rmap(fn, x, y), X, Y) -rmap(fn, X::NamedTuple) = map(x -> rmap(fn, x), X) -rmap(fn, X::NamedTuple{names}, Y::NamedTuple{names}) where {names} = - map((x, y) -> rmap(fn, x, y), X, Y) +rmap(fn::F, X) where {F} = fn(X) +rmap(fn::F, X, Y) where {F} = fn(X, Y) +rmap(fn::F, X::Tuple) where {F} = map(x -> rmap(fn, x), X) +rmap(fn::F, X::Tuple, Y::Tuple) where {F} = map((x, y) -> rmap(fn, x, y), X, Y) +rmap(fn::F, X::NamedTuple{names}) where {F, names} = + NamedTuple{names}(rmap(fn, Tuple(X))) +rmap(fn::F, X::NamedTuple{names}, Y::NamedTuple{names}) where {F, names} = + NamedTuple{names}(rmap(fn, Tuple(X), Tuple(Y))) """ rmaptype(fn, T) The return type of `rmap(fn, X::T)`. """ -rmaptype(fn, ::Type{T}) where {T} = fn(T) -rmaptype(fn, ::Type{T}) where {T <: Tuple} = +rmaptype(fn::F, ::Type{T}) where {F, T} = fn(T) +rmaptype(fn::F, ::Type{T}) where {F, T <: Tuple} = Tuple{map(fn, tuple(T.parameters...))...} -rmaptype(fn, ::Type{T}) where {T <: NamedTuple{names, tup}} where {names, tup} = +rmaptype( + fn::F, + ::Type{T}, +) where {F, T <: NamedTuple{names, tup}} where {names, tup} = NamedTuple{names, rmaptype(fn, tup)} - """ rmul(w, X) w ⊠ X @@ -66,7 +69,6 @@ const ⊟ = rsub rdiv(X, w::Number) = rmap(x -> x / w, X) - """ rmuladd(w, X, Y) @@ -76,7 +78,6 @@ rmuladd(w::Number, X, Y) = rmap((x, y) -> muladd(w, x, y), X, Y) rmuladd(X, w::Number, Y) = rmap((x, y) -> muladd(x, w, y), X, Y) rmuladd(w::Number, x::Number, y::Number) = muladd(w, x, y) - """ rmatmul1(W, S, i, j)