Search code examples
syntaxelm

What does the double colon ( :: ) mean in Elm?


I'm new to Elm and I just came across this:

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    UrlChange location ->
      ( { model | history = location :: model.history }
      , Cmd.none
)

Could someone tell me what the double colon does in line 5?


Solution

  • That's the cons operator. It adds an item to the front of a list.

    1 :: [2,3] == [1,2,3]
    1 :: [] == [1]
    

    Documentation:

    https://package.elm-lang.org/packages/elm/core/latest/List#::