elm

What do the empty parentheses `()` mean in Elm?

谁说我不能喝 提交于 2019-12-08 15:35:21
问题 I found out they are mean an empty tuple. However, are they also used as a convention by Elm programmers to mean "value can be ignored"? is13 : Int -> Result String () is13 code = if code == 13 then Ok () else Err "not the right key code" Source: https://github.com/pdamoc/elmChallenges/blob/master/challenge5.elm 回答1: The empty parentheses () are what's known as a unit type, that is, a type that can only ever have a single value. A tuple type with at least one item can have any number of

Chain http request and merge json response in ELM

我怕爱的太早我们不能终老 提交于 2019-12-08 06:33:32
问题 I've succeeded in triggering a simple http request in ELM and decoding the JSON response into an ELM value - [https://stackoverflow.com/questions/43139316/decode-nested-variable-length-json-in-elm] The problem I'm facing now- How to chain (concurrency preferred) two http requests and merge the json into my new (updated) model. Note - please see the updated Commands.elm Package used to access remote data - krisajenkins/remotedata http://package.elm-lang.org/packages/krisajenkins/remotedata/4.3

How do I pass connection-time websocket parameters to Phoenix from Elm?

霸气de小男生 提交于 2019-12-08 04:03:52
问题 I was following along Programming Phoenix but using Elm for my front end, rather than Javascript. The second part of that book describes how to use websockets. The book's running example has you create an authentication token for the client side to pass to Phoenix at connection creation time. The Javascript Socket class provided with Phoenix allows that, but there's no obvious way to do it in Elm (as of 0.17 and the date of this question). 回答1: As in the book, make the token visible to

Elm 0.17: How to subscribe to sibling/nested component changes

末鹿安然 提交于 2019-12-07 18:46:21
问题 See the full implementation with the suggestions of the accepted answer here: https://github.com/afcastano/elm-nested-component-communication ================================================================= I have one parent component with two children. See working example With the Elm Architecture, how can I update the right child when any of the counters in the left child change? At the moment, I have the parent component reading the nested property of the left child model and setting it

Chain http request and merge json response in ELM

倾然丶 夕夏残阳落幕 提交于 2019-12-07 15:05:30
I've succeeded in triggering a simple http request in ELM and decoding the JSON response into an ELM value - [https://stackoverflow.com/questions/43139316/decode-nested-variable-length-json-in-elm] The problem I'm facing now- How to chain (concurrency preferred) two http requests and merge the json into my new (updated) model. Note - please see the updated Commands.elm Package used to access remote data - krisajenkins/remotedata http://package.elm-lang.org/packages/krisajenkins/remotedata/4.3.0/RemoteData Github repo of my code - https://github.com/areai51/my-india-elm Previous Working Code -

Initialize model with current date

孤街醉人 提交于 2019-12-07 09:25:07
问题 I'm trying to initialize my model with the current date. I don't want to use a Native module. I'm trying to do it with Task and Effects. I'm stuck at my getCurrentTime method. What is the cleanest way? import Time exposing ( Time ) import StartApp import Task import Effects exposing (Never) import Html exposing ( Html ) app = StartApp.start { init = init , view = view , update = update , inputs = []} main = app.html port tasks : Signal (Task.Task Never ()) port tasks = app.tasks type alias

Elm: adding click events to SVG elements doesn't work – is this possible?

倖福魔咒の 提交于 2019-12-07 08:59:30
问题 I have been attempting to add an on "click" event to an SVG element in Elm in order to determine the relative position of the mouse click within that element. A code sample is given below that you can try running at http://elm-lang.org/try to show how click events on HTML elements seem to work as expected but not on SVG elements. In the sample, Html.on "click" is used rather than Html.onClick to allow the position data to be decoded from the event as explained in this discussion. After

Type inheritance in elm

岁酱吖の 提交于 2019-12-07 08:58:32
问题 What I am trying to achieve is type inheritance. What I mean by that is that I want to be able to have functions returning "sub-types" and then a function returning the "super-type". Let me give you an example let's say I have a main View component which returns an Html Msg view: Model -> Html Msg view model = div [class "goal-box"] [ function_a model, function_b model ] Now I would like function_a and function_b to each be able to return a subtype of Msg function_a: Model -> Html AMsg

Handling records with shared substructure in Elm

陌路散爱 提交于 2019-12-07 06:21:46
问题 I have some record types structured essentially like this: type Body x = { x | pos: (Int,Int) } type Bubble = Body { radius: Int } type Box = Body { width: Int, height: Int } Now I would like to have a mixed list of any of these and perform some operation on the Body part, but still special case handling Box and Bubble other times. For example, having (implementations elided): mv: (Int,Int) -> Body a -> Body a bubble: Bubble box: Box I would like to map (mv (1,1)) [box,bubble] but this fails

Decode a JSON tuple to Elm tuple

我的未来我决定 提交于 2019-12-07 05:55:38
问题 My JSON looks like the following { "resp": [ [1, "things"] , [2, "more things"] , [3, "even more things"] ] } the problem is that I can't parse the JSON tuples into Elm tuples: decodeThings : Decoder (List (Int, String)) decodeThings = field "resp" <| list <| map2 (,) int string It compiles, but when ran, it throws BadPayload "Expecting an Int at _.resp[2] but instead got [3, \"even more things\"] For some reason it reads [3, "even more things"] as only one thing and not as tuple in JSON