Extract data from a signal

前端 未结 2 1463
刺人心
刺人心 2020-12-21 12:19

I have a signal like this: signal1 = Signal.constant {a=4, b=3, l = []}
How do I extract a data from the signal?
I have tried Signal.map (\\x ->

2条回答
  •  无人及你
    2020-12-21 12:41

    This is deliberately near impossible, because you should not need to.

    Why? Well, it may help to look at one possible signature for main in an Elm application:

    main : Signal Element
    

    Here, we declare that the type of our program is a Signal of Element; this means that our program is an Element that changes over time. The Elm runtime will sort out the 'changing over time' bit for us, so long as we let it know what signals we care about (by referencing them), and how to connect them together (using map, foldp, and so on).

    If you are attempting to access the inner value to display it as part of your application - the right way to go is to use that main signature, and let Elm do the Signal unwrapping.

    If you just want to look at a value at runtime (in the console log, for example), take a look at:

    http://package.elm-lang.org/packages/elm-lang/core/2.1.0/Debug

提交回复
热议问题