@@ -89,15 +89,17 @@ class AsSubtype sub sup where
89 -- >>> duck ^? _Sub :: Maybe FourLeggedAnimal
89 -- >>> duck ^? _Sub :: Maybe FourLeggedAnimal
90 -- Nothing
90 -- Nothing
91 _Sub :: Prism' sup sub
91 _Sub :: Prism' sup sub
92− _Sub = prism injectSub projectSub
92+ _Sub = prism injectSub (\i -> maybe (Left i) Right (projectSub i))
94 -- |Injects a subtype into a supertype (upcast).
94 -- |Injects a subtype into a supertype (upcast).
95 injectSub :: sub -> sup
95 injectSub :: sub -> sup
96− injectSub = build (_Sub @sub @sup)
97+ = build (_Sub @sub @sup)
98 -- |Projects a subtype from a supertype (downcast).
99 -- |Projects a subtype from a supertype (downcast).
99− projectSub :: sup -> Either sup sub
100+ projectSub :: sup -> Maybe sub
100− projectSub = match (_Sub @sub @sup)
101+ projectSub
102+ = either (const Nothing) Just . match (_Sub @sub @sup)
102 {-# MINIMAL (injectSub, projectSub) | _Sub #-}
104 {-# MINIMAL (injectSub, projectSub) | _Sub #-}