Pipeline-friendly composition helpers
Using these allow to compose an "outer" optic with an "inner" other optic.
Optics in functional programming languages that support typeclasses can be expressed as functions that compose through the composition operator (just like any other functions) ; in Elm (plus typclasses), it would look like this:
lensAtoB >> lensBtoC >> lensCtoD == lensAtoD
lensAtoB >> optionalBtoC >> prismCtoD == optionalAtoCBut Elm doesn't support typeclasses, so we're stuck with defining composition functions that look similar like this:
import Monocle.Compose as Compose
lensAtoB
|> Compose.lensWithLens lensBtoC
|> Compose.lensWithLens lensCtoD
== lensAtoD
lensAtoB
|> Compose.lensWithOptional optionalBtoC
|> Compose.optionalWithPrism prismCtoD
== optionalAtoCThis is arguably more "discoverable" and maybe more readable, if more verbose.
pipeline-friendly composition between an outer Iso and an inner Prism (the result is a Prism)
ab : Iso A B
ab = ..
bc : Prism B C
bc = ..
ac : Prism A C
ac =
ab
|> ComposeIso.isoWithPrism bcpipeline-friendly composition between an outer Iso and an inner Lens (the result is a Lens)
ab : Iso A B
ab = ..
bc : Lens B C
bc = ..
ac : Lens A C
ac =
ab
|> ComposeIso.isoWithLens bcpipeline-friendly composition between an outer Iso and an inner Optional (the result is an Optional)
ab : Iso A B
ab = ..
bc : Optional B C
bc = ..
ac : Optional A C
ac =
ab
|> ComposeIso.isoWithOptional bcpipeline-friendly composition between an outer Prism and an inner Iso (the result is a Prism)
ab : Prism A B
ab = ..
bc : Iso B C
bc = ..
ac : Prism A C
ac =
ab
|> ComposePrism.prismWithIso bcpipeline-friendly composition between two Prisms
ab : Prism A B
ab = ..
bc : Prism B C
bc = ..
ac : Prism A C
ac =
ab
|> ComposePrism.prismWithPrism bcpipeline-friendly composition between an outer Prism and an inner Lens (the result is an Optional)
ab : Prism A B
ab = ..
bc : Lens B C
bc = ..
ac : Optional A C
ac =
ab
|> ComposePrism.prismWithLens bcpipeline-friendly composition between an outer Prism and an inner Optional (the result is an Optional)
ab : Prism A B
ab = ..
bc : Optional B C
bc = ..
ac : Optional A C
ac =
ab
|> ComposePrism.prismWithOptional bcpipeline-friendly composition between an outer Lens and an inner Iso (the result is a Lens)
ab : Lens A B
ab = ..
bc : Iso B C
bc = ..
ac : Lens A C
ac =
ab
|> Compose.lensWithIso bcpipeline-friendly composition between an outer Lens and an inner Prism (the result is an Optional)
ab : Lens A B
ab = ..
bc : Prism B C
bc = ..
ac : Optional A C
ac =
ab
|> Compose.lensWithPrism bcpipeline-friendly composition between two Lenses
ab : Lens A B
ab = ..
bc : Lens B C
bc = ..
ac : Lens A C
ac =
ab
|> Compose.lensWithLens bcpipeline-friendly composition between an outer Lens and an inner Optional (the result is an Optional)
ab : Lens A B
ab = ..
bc : Optional B C
bc = ..
ac : Optional A C
ac =
ab
|> Compose.lensWithOptional bcpipeline-friendly composition between an outer Optional and an inner Iso (the result is an Optional)
ab : Optional A B
ab = ..
bc : Iso B C
bc = ..
ac : Optional A C
ac =
ab
|> ComposeOptional.optionalWithIso bcpipeline-friendly composition between an outer Optional and an inner Prism (the result is an Optional)
ab : Optional A B
ab = ..
bc : Prism B C
bc = ..
ac : Optional A C
ac =
ab
|> ComposeOptional.withPrism bcpipeline-friendly composition between an outer Optional and an inner Lens (the result is an Optional)
ab : Optional A B
ab = ..
bc : Lens B C
bc = ..
ac : Optional A C
ac =
ab
|> ComposeOptional.optionalWithLens bcpipeline-friendly composition between two Optionals
ab : Optional A B
ab = ..
bc : Optional B C
bc = ..
ac : Optional A C
ac =
ab
|> ComposeOptional.optionalWithOptional bc
pipeline-friendly composition between two Iso