@@ -37,6 +37,9 @@ module Obelisk.Route.Frontend
3737 , maybeRoute
3838 , maybeRoute_
3939 , maybeRouted
40+ , eitherRoute
41+ , eitherRoute_
42+ , eitherRouted
4043 , runRouteViewT
4144 , SetRouteT(..)
4245 , SetRoute(..)
@@ -56,6 +59,7 @@ import Obelisk.Route
5659import Control.Category (Category (..), (.))
5760import Control.Category.Cartesian
5861import Control.Lens hiding (Bifunctor, bimap, universe, element)
62+import Control.Monad ((<=<))
5963import Control.Monad.Fix
6064import Control.Monad.Primitive
6165import Control.Monad.Ref
@@ -204,6 +208,20 @@ maybeRoute f = factorRouted $ strictDynWidget $ \(c :=> r') -> do
204208 runRoutedT (f c) r'
205209-}
206210
211+eitherRoute_
212+ :: (MonadFix m, MonadHold t m, Adjustable t m)
213+ => RoutedT t l m ()
214+ -> RoutedT t r m ()
215+ -> RoutedT t (Either l r) m ()
216+eitherRoute_ l r = eitherRouted $ strictDynWidget_ $ either (runRoutedT l) (runRoutedT r)
217+
218+eitherRoute
219+ :: (MonadFix m, MonadHold t m, Adjustable t m)
220+ => RoutedT t l m a
221+ -> RoutedT t r m a
222+ -> RoutedT t (Either l r) m (Dynamic t a)
223+eitherRoute l r = eitherRouted $ strictDynWidget $ either (runRoutedT l) (runRoutedT r)
224+
207225dsumValueCoercion :: Coercion f g -> Coercion (DSum k f) (DSum k g)
208226dsumValueCoercion Coercion = Coercion
209227
@@ -220,6 +238,9 @@ maybeRouted r = RoutedT $ ReaderT $ \d -> do
220238 d' <- maybeDyn d
221239 runRoutedT r d'
222240
241+eitherRouted :: (Reflex t, MonadFix m, MonadHold t m) => RoutedT t (Either (Dynamic t a) (Dynamic t b)) m c -> RoutedT t (Either a b) m c
242+eitherRouted r = RoutedT $ ReaderT $ runRoutedT r <=< eitherDyn
243+
223244-- | WARNING: The input 'Dynamic' must be fully constructed when this is run
224245strictDynWidget :: (MonadSample t m, MonadHold t m, Adjustable t m) => (a -> m b) -> RoutedT t a m (Dynamic t b)
225246strictDynWidget f = RoutedT $ ReaderT $ \r -> do