@@ -963,69 +963,131 @@ string_to_varname(str::AbstractString) = dict_to_varname(JSON.parse(str))
963963# ## Prefixing and unprefixing
964964
965965"""
966- _strip_identity (optic)
966+ _head (optic)
967967
968- Remove identity lenses from composed optics.
969- """
970- _strip_identity (:: Base.ComposedFunction{typeof(identity),typeof(identity)} ) = identity
971- function _strip_identity (o:: Base.ComposedFunction{Outer,typeof(identity)} ) where {Outer}
972- return _strip_identity (o. outer)
973- end
974- function _strip_identity (o:: Base.ComposedFunction{typeof(identity),Inner} ) where {Inner}
975- return _strip_identity (o. inner)
976- end
977- _strip_identity (o:: Base.ComposedFunction ) = o
978- _strip_identity (o:: Accessors.PropertyLens ) = o
979- _strip_identity (o:: Accessors.IndexLens ) = o
980- _strip_identity (o:: typeof (identity)) = o
981-
982- """
983- _inner(optic)
968+ Get the innermost layer of an optic.
984969
985- Get the innermost (non-identity) layer of an optic.
970+ !!! note
971+ Does not perform optic normalisation. You may wish to call
972+ `normalise(optic)` before using this function if the optic you are passing
973+ was not obtained from a VarName.
986974
987975```jldoctest; setup=:(using Accessors)
988- julia> AbstractPPL._inner (Accessors.@o _.a.b.c)
976+ julia> AbstractPPL._head (Accessors.@o _.a.b.c)
989977(@o _.a)
990978
991- julia> AbstractPPL._inner (Accessors.@o _[1][2][3])
979+ julia> AbstractPPL._head (Accessors.@o _[1][2][3])
992980(@o _[1])
993981
994- julia> AbstractPPL._inner(Accessors.@o _)
982+ julia> AbstractPPL._head(Accessors.@o _.a)
983+ (@o _.a)
984+
985+ julia> AbstractPPL._head(Accessors.@o _[1])
986+ (@o _[1])
987+
988+ julia> AbstractPPL._head(Accessors.@o _)
995989identity (generic function with 1 method)
996990```
997991"""
998- _inner (o:: Base. ComposedFunction{Outer,Inner} ) where {Outer,Inner} = o. inner
999- _inner (o:: Accessors.PropertyLens ) = o
1000- _inner (o:: Accessors.IndexLens ) = o
1001- _inner (o :: typeof (identity)) = o
992+ _head (o:: ComposedFunction{Outer,Inner} ) where {Outer,Inner} = o. inner
993+ _head (o:: Accessors.PropertyLens ) = o
994+ _head (o:: Accessors.IndexLens ) = o
995+ _head ( :: typeof (identity)) = identity
1002996
1003997"""
1004- _outer(optic)
998+ _tail(optic)
999+
1000+ Get everything but the innermost layer of an optic.
10051001
1006- Get the outer layer of an optic.
1002+ !!! note
1003+ Does not perform optic normalisation. You may wish to call
1004+ `normalise(optic)` before using this function if the optic you are passing
1005+ was not obtained from a VarName.
10071006
10081007```jldoctest; setup=:(using Accessors)
1009- julia> AbstractPPL._outer (Accessors.@o _.a.b.c)
1008+ julia> AbstractPPL._tail (Accessors.@o _.a.b.c)
10101009(@o _.b.c)
10111010
1012- julia> AbstractPPL._outer (Accessors.@o _[1][2][3])
1011+ julia> AbstractPPL._tail (Accessors.@o _[1][2][3])
10131012(@o _[2][3])
10141013
1015- julia> AbstractPPL._outer (Accessors.@o _.a)
1014+ julia> AbstractPPL._tail (Accessors.@o _.a)
10161015identity (generic function with 1 method)
10171016
1018- julia> AbstractPPL._outer (Accessors.@o _[1])
1017+ julia> AbstractPPL._tail (Accessors.@o _[1])
10191018identity (generic function with 1 method)
10201019
1021- julia> AbstractPPL._outer (Accessors.@o _)
1020+ julia> AbstractPPL._tail (Accessors.@o _)
10221021identity (generic function with 1 method)
10231022```
10241023"""
1025- _outer (o:: Base.ComposedFunction{Outer,Inner} ) where {Outer,Inner} = o. outer
1026- _outer (:: Accessors.PropertyLens ) = identity
1027- _outer (:: Accessors.IndexLens ) = identity
1028- _outer (:: typeof (identity)) = identity
1024+ _tail (o:: ComposedFunction{Outer,Inner} ) where {Outer,Inner} = o. outer
1025+ _tail (:: Accessors.PropertyLens ) = identity
1026+ _tail (:: Accessors.IndexLens ) = identity
1027+ _tail (:: typeof (identity)) = identity
1028+
1029+ """
1030+ _last(optic)
1031+
1032+ Get the outermost layer of an optic.
1033+
1034+ !!! note
1035+ Does not perform optic normalisation. You may wish to call
1036+ `normalise(optic)` before using this function if the optic you are passing
1037+ was not obtained from a VarName.
1038+
1039+ ```jldoctest; setup=:(using Accessors)
1040+ julia> AbstractPPL._last(Accessors.@o _.a.b.c)
1041+ (@o _.c)
1042+
1043+ julia> AbstractPPL._last(Accessors.@o _[1][2][3])
1044+ (@o _[3])
1045+
1046+ julia> AbstractPPL._last(Accessors.@o _.a)
1047+ (@o _.a)
1048+
1049+ julia> AbstractPPL._last(Accessors.@o _[1])
1050+ (@o _[1])
1051+
1052+ julia> AbstractPPL._last(Accessors.@o _)
1053+ identity (generic function with 1 method)
1054+ ```
1055+ """
1056+ _last (o:: ComposedFunction{Outer,Inner} ) where {Outer,Inner} = _last (o. outer)
1057+ _last (o:: Accessors.PropertyLens ) = o
1058+ _last (o:: Accessors.IndexLens ) = o
1059+ _last (:: typeof (identity)) = identity
1060+
1061+ """
1062+ _init(optic)
1063+
1064+ Get everything but the outermost layer of an optic.
1065+
1066+ !!! note
1067+ Does not perform optic normalisation. You may wish to call
1068+ `normalise(optic)` before using this function if the optic you are passing
1069+ was not obtained from a VarName.
1070+
1071+ ```jldoctest; setup=:(using Accessors)
1072+ julia> AbstractPPL._init(Accessors.@o _.a.b.c)
1073+ (@o _.a.b)
1074+
1075+ julia> AbstractPPL._init(Accessors.@o _[1][2][3])
1076+ (@o _[1][2])
1077+
1078+ julia> AbstractPPL._init(Accessors.@o _.a)
1079+ identity (generic function with 1 method)
1080+
1081+ julia> AbstractPPL._init(Accessors.@o _[1])
1082+ identity (generic function with 1 method)
1083+
1084+ julia> AbstractPPL._init(Accessors.@o _)
1085+ identity (generic function with 1 method)
1086+ """
1087+ _init (o:: ComposedFunction{Outer,Inner} ) where {Outer,Inner} = _init (o. outer) ∘ o. inner
1088+ _init (:: Accessors.PropertyLens ) = identity
1089+ _init (:: Accessors.IndexLens ) = identity
1090+ _init (:: typeof (identity)) = identity
10291091
10301092"""
10311093 optic_to_vn(optic)
@@ -1058,11 +1120,11 @@ function optic_to_vn(::Accessors.PropertyLens{sym}) where {sym}
10581120 return VarName {sym} ()
10591121end
10601122function optic_to_vn (
1061- o:: Base. ComposedFunction{Outer,Accessors.PropertyLens{sym}}
1123+ o:: ComposedFunction{Outer,Accessors.PropertyLens{sym}}
10621124) where {Outer,sym}
10631125 return VarName {sym} (o. outer)
10641126end
1065- optic_to_vn (o:: Base. ComposedFunction ) = optic_to_vn (normalise (o))
1127+ optic_to_vn (o:: ComposedFunction ) = optic_to_vn (normalise (o))
10661128function optic_to_vn (@nospecialize (o))
10671129 msg = " optic_to_vn: could not convert optic `$o ` to a VarName"
10681130 throw (ArgumentError (msg))
@@ -1077,14 +1139,14 @@ function unprefix_optic(optic, optic_prefix)
10771139 optic = normalise (optic)
10781140 optic_prefix = normalise (optic_prefix)
10791141 # strip one layer of the optic and check for equality
1080- inner = _inner (optic)
1081- inner_prefix = _inner (optic_prefix)
1082- if inner != inner_prefix
1142+ head = _head (optic)
1143+ head_prefix = _head (optic_prefix)
1144+ if head != head_prefix
10831145 msg = " could not remove prefix $(optic_prefix) from optic $(optic) "
10841146 throw (ArgumentError (msg))
10851147 end
10861148 # recurse
1087- return unprefix_optic (_outer (optic), _outer (optic_prefix))
1149+ return unprefix_optic (_tail (optic), _tail (optic_prefix))
10881150end
10891151
10901152"""
0 commit comments