Structuring a dynamic list of reflex-dom widgets/events according to numeric user input

Viewed 501

I'm trying to create a dynamic list of widgets with the number of widgets determined by a numeric value from user input. Furthermore, each widget returns a click event. Here's what I'm using to get the user input:

settings :: MonadWidget t m => m (Dynamic t (Maybe Int))

Then I use this to generate a list of random number generators (The fact that these are values of RandomGen is not significant. They're just used for the content of each element, not the number of elements).:

split' :: RandomGen g => Int -> g -> [g]
-- ...

gs <- mapDyn (maybe (split' 1 g) (flip split' g)) =<< settings

Now I have gs :: (MonadWidget t m, RandomGen g) => Dynamic t [g]. One g for each widget. These widgets return Event values so I'll need to combine them (i.e. leftmost) then use that value with foldDyn somewhere.

go :: (MonadWidget t m, Random g) => g -> m (Event t MyType)
-- ...

clicked <- el "div" $ do
  -- omg
  xs <- simpleList gs go

  -- would like to eventually do this
  dynEvent <- mapDyn leftmost xs
  return $ switch (current dynEvent)

But so far I end up with xs :: Dynamic t [Dynamic t (m (Event t MyType))].

I think what I really need is to somehow make xs :: MonadWidget t m => Dynamic t [Event t MyType] instead but having some trouble getting there even with other functions aside from simpleList.

1 Answers
Related