What is the "extraction" syntax in transformation functions called? #1978
-
Hi all, In the VoiceMemos example (and elsewhere), mapping/transformation functions such as action: /Action.voiceMemo(id:action:)
Cheers! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @andwrobs! There are various things at play here, but you should have a look at A You can form a Enum's cases with associated values are promoted to static functions of this exact shape when used without argument. For example: enum E {
case s(String)
}
So what you see in your example is a custom prefix operator. Namely [ / + (UUID, VoiceMemo.Action) -> Action ] ~> CasePath.init(embed: (UUID, VoiceMemo.Action) -> Action) ~> CasePath<Action, VoiceMemo.Action> I don't know if this is clear! There is indeed a bunch of medium/high level features involved for this to work, but |
Beta Was this translation helpful? Give feedback.
Hey @andwrobs! There are various things at play here, but you should have a look at
CasePaths
for more informations about the inner bits.A
CasePath
is something similar to aKeyPath
that is able to extract/embed associated values for a given enum's case.You can form a
CasePath
using explicitextract
andembed
implementations, but the library is also able to perform some reflection magic and to create a completeCasePath
from a function(AssociatedValue) -> Enum
.Enum's cases with associated values are promoted to static functions of this exact shape when used without argument. For example:
E.s
is inferred as a function(String) -> E
, becauseE.s evaluated wit…