1

I'm writing a GUI app in Monomer which has a textField function which accepts ALens which it uses to read/write input value into an AppModel .

In my case AppModel looks like this:

data AppModel = AppModel
  { _activeComment :: Maybe Text
  }
  deriving (Eq, Show)

And so I'm using this lens:

textField (activeComment . non "")

I use non "" to get a default value, because textField requres a lens with Text focus.

Now I have these questions (I am only learning Lens):

  1. Suppose I want to map user input and apply "h"-symbol to every key they type, how would I do that? I.e. I want to insert (\t -> t <> "h") mapping somewhere, but I can't figure out how. What is the operator I should use here? Is that from realm of Isos? (didn't learn them yet)
  2. What if I want to perform an effect on each key press, wait for the result and then set to to a lens focus? I guess this is not possible with current types. And this is probably more of a library question than a lens question, but still.

P.S. Here's an example of using textField from library samples in case docs are not enough: example

dimsuz
  • 8,969
  • 8
  • 54
  • 88
  • I'm not sure about the library in general, but if you need an `Iso`, it feels like it shouldn't be hard to make. Perhaps `withH = iso init (flip snoc 'h')`? – DDub Dec 11 '22 at 23:12

0 Answers0