Skip to content

Instantly share code, notes, and snippets.

@HusseinMorsy
Last active July 30, 2016 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HusseinMorsy/8c726fc58be40722a147488db9da33e3 to your computer and use it in GitHub Desktop.
Save HusseinMorsy/8c726fc58be40722a147488db9da33e3 to your computer and use it in GitHub Desktop.
Elm examples which outs a Shopping list. Every step outputs the same HTML
<div>
<h1>Shopping List</h1>
<ul>
<li>Apples</li>
<li>Tomatos</li>
<li>Banana</li>
</ul>
</div>
module Main exposing (..)
import Html exposing (..)
main =
div []
[ h1 [] [ text "Shoppint List" ]
, ul []
[ li [] [ text "Apples" ]
, li [] [ text "Tomatos" ]
, li [] [ text "Banana" ]
]
]
module Main exposing (..)
import Html exposing (..)
main =
view
view =
div []
[ viewTitle "Shoppting List"
, viewList
]
viewTitle title =
h1 [] [ text title ]
viewList =
ul []
[ viewItem "Apples"
, viewItem "Tomatos"
, viewItem "Banana"
]
viewItem item =
li [] [ text item ]
module Main exposing (..)
import Html exposing (..)
main =
view
view =
div []
[ viewTitle "Shoppting List"
, viewList [ "Apples", "Tomatos", "Banana" ]
]
viewTitle title =
h1 [] [ text title ]
viewList list =
ul [] (List.map viewItem list)
viewItem item =
li [] [ text item ]
module Main exposing (..)
import Html exposing (..)
model =
{ title = "Shoppting List", items = [ "Apples", "Tomatos", "Banana" ] }
main =
view model
view model =
div []
[ viewTitle model.title
, viewList model.items
]
viewTitle title =
h1 [] [ text title ]
viewList list =
ul [] (List.map viewItem list)
viewItem item =
li [] [ text item ]
module Main exposing (..)
import Html exposing (..)
type alias Model =
{ title : String, items : List Item }
type alias Item =
String
model : Model
model =
{ title = "Shoppting List", items = [ "Apples", "Tomatos", "Banana" ] }
main : Html a
main =
view model
view : Model -> Html a
view model =
div []
[ viewTitle model.title
, viewList model.items
]
viewTitle : String -> Html a
viewTitle title =
h1 [] [ text title ]
viewList : List Item -> Html a
viewList list =
ul [] (List.map viewItem list)
viewItem : Item -> Html a
viewItem item =
li [] [ text item ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment