Skip to content

Commit 83c1454

Browse files
Merge pull request #24 from oschulz/composed_function
Support Base.ComposedFunction
2 parents aeb4e72 + 1fec6b3 commit 83c1454

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/functor.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ functor(::Type{<:NamedTuple}, x) = x, y -> y
77
functor(::Type{<:AbstractArray}, x) = x, y -> y
88
functor(::Type{<:AbstractArray{<:Number}}, x) = (), _ -> x
99

10+
@static if VERSION >= v"1.6"
11+
functor(::Type{<:Base.ComposedFunction}, x) = (outer = x.outer, inner = x.inner), y -> Base.ComposedFunction(y.outer, y.inner)
12+
end
13+
1014
function makefunctor(m::Module, T, fs = fieldnames(T))
1115
yᵢ = 0
1216
escargs = map(fieldnames(T)) do f

test/basics.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ struct NoChildren
2323
y
2424
end
2525

26+
@static if VERSION >= v"1.6"
27+
@testset "ComposedFunction" begin
28+
f1 = Foo(1.1, 2.2)
29+
f2 = Bar(3.3)
30+
@test Functors.functor(f1 f2)[1] == (outer = f1, inner = f2)
31+
@test Functors.functor(f1 f2)[2]((outer = f1, inner = f2)) == f1 f2
32+
@test fmap(x -> x + 10, f1 f2) == Foo(11.1, 12.2) Bar(13.3)
33+
end
34+
end
35+
2636
@testset "Nested" begin
2737
model = Bar(Foo(1, [1, 2, 3]))
2838

0 commit comments

Comments
 (0)