Skip to content

Commit 89b2b42

Browse files
committed
Clean up code a bit
1 parent 9d0ff71 commit 89b2b42

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/varname.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -944,9 +944,15 @@ string_to_varname(str::AbstractString) = dict_to_varname(JSON.parse(str))
944944
"""
945945
_strip_identity(optic)
946946
947-
Remove an inner layer of the identity lens from a composed optic.
947+
Remove identity lenses from composed optics.
948948
"""
949-
_strip_identity(o::Base.ComposedFunction{Outer,typeof(identity)}) where {Outer} = o.outer
949+
_strip_identity(::Base.ComposedFunction{typeof(identity),typeof(identity)}) = identity
950+
function _strip_identity(o::Base.ComposedFunction{Outer,typeof(identity)}) where {Outer}
951+
return _strip_identity(o.outer)
952+
end
953+
function _strip_identity(o::Base.ComposedFunction{typeof(identity),Inner}) where {Inner}
954+
return _strip_identity(o.inner)
955+
end
950956
_strip_identity(o::Base.ComposedFunction) = o
951957
_strip_identity(o::Accessors.PropertyLens) = o
952958
_strip_identity(o::Accessors.IndexLens) = o
@@ -969,9 +975,7 @@ identity (generic function with 1 method)
969975
```
970976
"""
971977
_inner(o::Base.ComposedFunction{Outer,Inner}) where {Outer,Inner} = o.inner
972-
function _inner(o::Base.ComposedFunction{Outer,typeof(identity)}) where {Outer}
973-
return _strip_identity(o.outer)
974-
end
978+
_inner(o::Base.ComposedFunction{Outer,typeof(identity)}) where {Outer} = o.outer
975979
_inner(o::Accessors.PropertyLens) = o
976980
_inner(o::Accessors.IndexLens) = o
977981
_inner(o::typeof(identity)) = o
@@ -998,7 +1002,7 @@ julia> AbstractPPL._outer(Accessors.@o _)
9981002
identity (generic function with 1 method)
9991003
```
10001004
"""
1001-
_outer(o::Base.ComposedFunction{Outer,Inner}) where {Outer,Inner} = _strip_identity(o.outer)
1005+
_outer(o::Base.ComposedFunction{Outer,Inner}) where {Outer,Inner} = o.outer
10021006
_outer(::Accessors.PropertyLens) = identity
10031007
_outer(::Accessors.IndexLens) = identity
10041008
_outer(::typeof(identity)) = identity
@@ -1049,14 +1053,16 @@ end
10491053
unprefix_optic(o, ::typeof(identity)) = o # Base case
10501054
function unprefix_optic(optic, optic_prefix)
10511055
# strip one layer of the optic and check for equality
1052-
inner = _inner(optic)
1053-
inner_prefix = _inner(optic_prefix)
1056+
inner = _inner(_strip_identity(optic))
1057+
inner_prefix = _inner(_strip_identity(optic_prefix))
10541058
if inner != inner_prefix
10551059
msg = "could not remove prefix $(optic_prefix) from optic $(optic)"
10561060
throw(ArgumentError(msg))
10571061
end
10581062
# recurse
1059-
return unprefix_optic(_outer(optic), _outer(optic_prefix))
1063+
return unprefix_optic(
1064+
_outer(_strip_identity(optic)), _outer(_strip_identity(optic_prefix))
1065+
)
10601066
end
10611067

10621068
"""

0 commit comments

Comments
 (0)