@@ -963,69 +963,131 @@ string_to_varname(str::AbstractString) = dict_to_varname(JSON.parse(str))
963
963
# ## Prefixing and unprefixing
964
964
965
965
"""
966
- _strip_identity (optic)
966
+ _head (optic)
967
967
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.
984
969
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.
986
974
987
975
```jldoctest; setup=:(using Accessors)
988
- julia> AbstractPPL._inner (Accessors.@o _.a.b.c)
976
+ julia> AbstractPPL._head (Accessors.@o _.a.b.c)
989
977
(@o _.a)
990
978
991
- julia> AbstractPPL._inner (Accessors.@o _[1][2][3])
979
+ julia> AbstractPPL._head (Accessors.@o _[1][2][3])
992
980
(@o _[1])
993
981
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 _)
995
989
identity (generic function with 1 method)
996
990
```
997
991
"""
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
1002
996
1003
997
"""
1004
- _outer(optic)
998
+ _tail(optic)
999
+
1000
+ Get everything but the innermost layer of an optic.
1005
1001
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.
1007
1006
1008
1007
```jldoctest; setup=:(using Accessors)
1009
- julia> AbstractPPL._outer (Accessors.@o _.a.b.c)
1008
+ julia> AbstractPPL._tail (Accessors.@o _.a.b.c)
1010
1009
(@o _.b.c)
1011
1010
1012
- julia> AbstractPPL._outer (Accessors.@o _[1][2][3])
1011
+ julia> AbstractPPL._tail (Accessors.@o _[1][2][3])
1013
1012
(@o _[2][3])
1014
1013
1015
- julia> AbstractPPL._outer (Accessors.@o _.a)
1014
+ julia> AbstractPPL._tail (Accessors.@o _.a)
1016
1015
identity (generic function with 1 method)
1017
1016
1018
- julia> AbstractPPL._outer (Accessors.@o _[1])
1017
+ julia> AbstractPPL._tail (Accessors.@o _[1])
1019
1018
identity (generic function with 1 method)
1020
1019
1021
- julia> AbstractPPL._outer (Accessors.@o _)
1020
+ julia> AbstractPPL._tail (Accessors.@o _)
1022
1021
identity (generic function with 1 method)
1023
1022
```
1024
1023
"""
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
1029
1091
1030
1092
"""
1031
1093
optic_to_vn(optic)
@@ -1058,11 +1120,11 @@ function optic_to_vn(::Accessors.PropertyLens{sym}) where {sym}
1058
1120
return VarName {sym} ()
1059
1121
end
1060
1122
function optic_to_vn (
1061
- o:: Base. ComposedFunction{Outer,Accessors.PropertyLens{sym}}
1123
+ o:: ComposedFunction{Outer,Accessors.PropertyLens{sym}}
1062
1124
) where {Outer,sym}
1063
1125
return VarName {sym} (o. outer)
1064
1126
end
1065
- optic_to_vn (o:: Base. ComposedFunction ) = optic_to_vn (normalise (o))
1127
+ optic_to_vn (o:: ComposedFunction ) = optic_to_vn (normalise (o))
1066
1128
function optic_to_vn (@nospecialize (o))
1067
1129
msg = " optic_to_vn: could not convert optic `$o ` to a VarName"
1068
1130
throw (ArgumentError (msg))
@@ -1077,14 +1139,14 @@ function unprefix_optic(optic, optic_prefix)
1077
1139
optic = normalise (optic)
1078
1140
optic_prefix = normalise (optic_prefix)
1079
1141
# 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
1083
1145
msg = " could not remove prefix $(optic_prefix) from optic $(optic) "
1084
1146
throw (ArgumentError (msg))
1085
1147
end
1086
1148
# recurse
1087
- return unprefix_optic (_outer (optic), _outer (optic_prefix))
1149
+ return unprefix_optic (_tail (optic), _tail (optic_prefix))
1088
1150
end
1089
1151
1090
1152
"""
0 commit comments