{-# LANGUAGE CPP #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecursiveDo #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.Widget.Basic where
import Control.Monad.Fix (MonadFix)
import Data.Map (Map)
import Reflex.Class
import Reflex.Adjustable.Class
import Data.Patch.MapWithMove
sortableList :: forall t m k v a. (MonadHold t m, MonadFix m, Adjustable t m, Ord k)
=> (k -> v -> m a)
-> Map k v
-> Event t (v -> v -> Ordering)
-> m (Map k a)
sortableList :: (k -> v -> m a)
-> Map k v -> Event t (v -> v -> Ordering) -> m (Map k a)
sortableList f :: k -> v -> m a
f m0 :: Map k v
m0 reSortFunc :: Event t (v -> v -> Ordering)
reSortFunc = do
rec let reSortPatch :: Event t (PatchMapWithMove k v)
reSortPatch = (Map k v -> (v -> v -> Ordering) -> PatchMapWithMove k v)
-> Behavior t (Map k v)
-> Event t (v -> v -> Ordering)
-> Event t (PatchMapWithMove k v)
forall k (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Behavior t a -> Event t b -> Event t c
attachWith (((v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v)
-> Map k v -> (v -> v -> Ordering) -> PatchMapWithMove k v
forall a b c. (a -> b -> c) -> b -> a -> c
flip (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v
forall k v.
Ord k =>
(v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v
patchThatSortsMapWith) (Incremental t (PatchMapWithMove k v)
-> Behavior t (PatchTarget (PatchMapWithMove k v))
forall k (t :: k) p.
(Reflex t, Patch p) =>
Incremental t p -> Behavior t (PatchTarget p)
currentIncremental Incremental t (PatchMapWithMove k v)
m) Event t (v -> v -> Ordering)
reSortFunc
Incremental t (PatchMapWithMove k v)
m <- PatchTarget (PatchMapWithMove k v)
-> Event t (PatchMapWithMove k v)
-> m (Incremental t (PatchMapWithMove k v))
forall k (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental Map k v
PatchTarget (PatchMapWithMove k v)
m0 Event t (PatchMapWithMove k v)
reSortPatch
(results :: Map k a
results, _) <- (k -> v -> m a)
-> Map k v
-> Event t (PatchMapWithMove k v)
-> m (Map k a, Event t (PatchMapWithMove k a))
forall t (m :: * -> *) k v v'.
(Adjustable t m, Ord k) =>
(k -> v -> m v')
-> Map k v
-> Event t (PatchMapWithMove k v)
-> m (Map k v', Event t (PatchMapWithMove k v'))
mapMapWithAdjustWithMove k -> v -> m a
f Map k v
m0 Event t (PatchMapWithMove k v)
reSortPatch
Map k a -> m (Map k a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map k a
results