@@ -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 _)
9981002identity (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
10491053unprefix_optic (o, :: typeof (identity)) = o # Base case
10501054function 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+ )
10601066end
10611067
10621068"""
0 commit comments