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):
- 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 ofIso
s? (didn't learn them yet) - 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