elm

Concise way of updating a nested value inside a record in Elm (0.18)

心不动则不痛 提交于 2019-12-18 13:06:17
问题 I am looking for a concise way of updating a nested value inside a record in Elm (0.18). Given the following example: person = { name = "Steven", address = { country = "Spain", city = "Barcelona" } } I can update person.name to "Steve" using the following expression: { person | name = "Steve" } However, I am looking for a way to update a nested value. For instance, I would like to update person.address.city to "Madrid". I tried the following: { person | address.city = "Madrid" } { person |

What does “! []” Elm code syntax in Todomvc mean

白昼怎懂夜的黑 提交于 2019-12-18 11:38:50
问题 Coming from react, I am learning to understand Elm. In the Todomvc example code, there is the following code snippet: -- How we update our Model on a given Msg? update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of NoOp -> model ! [] <-- What is this? What I (think I) understand, is that the update function takes in a msg of type Msg and a model of type Model , and returns a tuple of containing a Model and a Cmd Msg . But how should I read the return statement? model ! []

What does comparable mean in Elm?

久未见 提交于 2019-12-18 04:45:05
问题 I'm having trouble understanding what exactly a comparable is in Elm. Elm seems as confused as I am. On the REPL: > f1 = (<) <function> : comparable -> comparable -> Bool So f1 accepts comparables. > "a" "a" : String > f1 "a" "b" True : Bool So it seems String is comparable. > f2 = (<) 1 <function> : comparable -> Bool So f2 accepts a comparable. > f2 "a" As I infer the type of values flowing through your program, I see a conflict between these two types: comparable String So String is and is

Sequence Http.get in Elm

我的梦境 提交于 2019-12-14 03:46:23
问题 Below I have a button that attempts to load remote content ... import Post exposing (Post) import Html exposing (..) import Html.Events exposing (..) import Http import Json.Decode as Decode type alias Model = { posts : List Post } type Msg = Search String | PostsReceived (Result Http.Error (List Post)) update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of Search s -> let cmd = (Decode.list Post.decode) |> Http.get ("/posts?author=" ++ s) |> Http.send PostsReceived in (

Getting the page scrollTop value in elm

帅比萌擦擦* 提交于 2019-12-14 01:32:38
问题 I have started playing around with the language Elm. I am making a basic web page and I would like to make my nav bar stick to the top when scrolling. I would like to be able to make my model react to the distance scrolled down from the top of the page. I have two problems: How to access this variable with Javascript? Ideally I would like something like JQuery's $(window).scrollTop() but without JQuery How to pass this value back to Elm? Do I have to set up a port? 回答1: You'll need to set up

Initializing an empty file value in Elm

柔情痞子 提交于 2019-12-13 21:50:32
问题 I am using Elm (0.18) and imported simonh1000's FileReader library. To store a file value, we use the following type: import Json.Decode as Json exposing (Decoder, Value) ... {-| An ArrayBuffer is a Elm Json Value. -} type alias FileContentArrayBuffer = Value I want to initialize my model with an empty placeholder. I do this as follows: type alias Model = { username : String , filecontent: FileContentArrayBuffer } initialModel : Model initialModel = { username = "mark" , filecontent = Nothing

Generating unique random number

两盒软妹~` 提交于 2019-12-13 17:30:20
问题 I have an application that I want to generate a list of 5 unique numbers on init three times after reading a json. So basically I want to get something like [31, 59, 62, 72, 2, 16, 2, 38, 94, 15, 55, 46, 83, 2, 10]. My challenge is that I am new to functional programming and elm and I am a bit lost. So I understand that Random.generate takes a msg and a generator and returns a cmd message and it is mostly used in the update function but this is not where I need as it is a helper function and

Elm JSON decoder for Union type with data

▼魔方 西西 提交于 2019-12-12 23:40:26
问题 My json looks like this: {"name": "providerWithVal", "value": "example"} or like this: {"name": "provider2"} or {"name": "provider3"} My Elm union type is defined like so: type Provider = ProviderWithVal String | Provider2 | Provider3 I can write a decoder for a union type without data attached. But ProviderWithVal takes a string and I'm not sure how to make it all work. This is what I have so far: import Json.Decode as D providerDecoder : D.Decoder Provider providerDecoder = D.field "name" D

Updating a record in Elm

前提是你 提交于 2019-12-12 20:01:15
问题 NOTE: This is my first time ever looking at Elm and I just learned about its existence last week by accident. When you update a record, are you really updating a record or just creating a new one. > { bill | name = "Nye" } { age = 57, name = "Nye" } > { bill | age = 22 } { age = 22, name = "Gates" } I would expect: > { age = 22, name = "Nye" } Since there were two updates done on 'bill'. Reading from the Elm language site, I know there aren't destructive updates. A new object (with the same

elm: read file content

ぃ、小莉子 提交于 2019-12-12 19:46:46
问题 Is there a way to read a file in elm ? I want to have an xml settings file where I will keep different settings and read it with elm (I've seen this parser, but it expects the xml content, not path). I don't want to use ports and these stuff. I need to apply some transformations to this xml because I will have more sets of values (staging and production) and I will need to generate an artefact for each value (I'm using TFS for this). 回答1: As of today ( 0.18.0 ), officially Elm does not