Welcome to Elm - 3.4 Array

  Рет қаралды 180

Ryan Haskell

Ryan Haskell

Күн бұрын

Learn how to work with arrays and indexes in Elm

Пікірлер: 4
@coder_one
@coder_one 2 ай бұрын
I have a question from another thread - I want to write a package to publish on elm-packages. The task of the package will be to support a certain API provided by the browser and a 3rd party library from the JS ecosystem, so I will have to use ports to communicate with each other elm and JS. The problem for me is the "javascript" part of the code responsible for ports - it is required there to call the function that initializes Elm, and on this instance to call the corresponding methods that communicate with ports. Only as a package developer I have no knowledge of how the end-user initializes Elm (whether he uses an HTML element with id "elm" or another) etc. I have not found valuable information on the web about writing and publishing such packages whose purpose is to provide ports to a specific external JS API. How to do this correctly?
@borkomne
@borkomne 5 ай бұрын
What happens if you set 5th element on array of size 3?
@HeyRyanHaskell
@HeyRyanHaskell 5 ай бұрын
That's a GREAT question! Something that surprised me when first working with Arrays in Elm (coming from JS) is that you can't set indices past the array's size. So in our specific example if we tried this: Array.set 5 "hi" (Array.fromList [ "ryan", "scott", "alexa" ]) It would NOT insert "hi"! In the next video we cover the "Dict" type: Dict.insert 5 "hi" (Dict.fromList [ (0,"ryan"), (1,"scott"), (2,"alexa") ]) Calling insert on a dictionary works fine! It will add "hi" in the place we expect: Dict.fromList [ (0,"ryan"), (1,"scott"), (2,"alexa"), (5, "hi") ] Hope this explanation makes sense!
@borkomne
@borkomne 5 ай бұрын
Thanks!
Welcome to Elm - 3.5 Dict
6:46
Ryan Haskell
Рет қаралды 218
Welcome to Elm - 5.6 Commands
14:19
Ryan Haskell
Рет қаралды 226
Yay, My Dad Is a Vending Machine! 🛍️😆 #funny #prank #comedy
00:17
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 31 МЛН
Каха и лужа  #непосредственнокаха
00:15
Welcome to Elm - 7.2 File Structure
27:10
Ryan Haskell
Рет қаралды 332
Welcome to Elm - 6.4 Ports
16:57
Ryan Haskell
Рет қаралды 317
Welcome to Elm - 5.5 Subscriptions
13:40
Ryan Haskell
Рет қаралды 241
Welcome to Elm - 5.1 React to Elm
9:34
Ryan Haskell
Рет қаралды 440
Welcome to Elm - 7.3 Browser.application
14:56
Ryan Haskell
Рет қаралды 254
Welcome to Elm - 6.3 Flags
10:20
Ryan Haskell
Рет қаралды 279
Welcome to Elm - 7.4 Context & Effect
40:30
Ryan Haskell
Рет қаралды 581
Welcome to Elm - 6.5 Web Components
21:50
Ryan Haskell
Рет қаралды 386
Welcome to Elm - 5.2 The Elm Architecture
7:57
Ryan Haskell
Рет қаралды 332