2

Currently I'm experimenting with elm (so consider me a beginner) and was wondering about the following,

I have defined the following model :

model = foldp update initialModel actions.signal

I understand how foldp works, it calls my update method to change the initialModel whenever an action is performed (called from my html buttons etc).

However, now I'm struggling to find out how I can integrate keypresses into this model since foldp only accepts a single changing signal.

So I would like to get something like this

model = foldp update initialModel (actions.signal + Keyboard.arrows)

I tried to play around with the merge method but I just can't seem to be able to get it working.

Thanks!

Apanatshka
  • 5,958
  • 27
  • 38
Koen Certyn
  • 193
  • 3

2 Answers2

2

Given that you have an actions mailbox, do you have an Action type defined too? Then you can expand it to include a Keypress action:

type Action =
  ...
  | KeyPress { x : Int, y : Int }

inputs =
  Signal.merge actions.signal (Signal.map KeyPress Keyboard.arrows)

model =
  Signal.foldp update initialModel inputs
Apanatshka
  • 5,958
  • 27
  • 38
0

You want to use Signal.merge - take a look at http://elm-lang.org/guide/reactivity#signals for an overview of the signal map

Simon H
  • 20,332
  • 14
  • 71
  • 128