跳轉到內容

99 個 Elm 問題/問題 1

來自 Wikibooks,開放世界中的開放書籍

找到列表的最後一個元素。

測試應用程式

[編輯 | 編輯原始碼]

在這個測試應用程式中實現 lastElement

module Main exposing (..)

import Html exposing (text)
import List
import Maybe

lastElement : List a -> Maybe a
lastElement list = 
  -- your implementation goes here
  Nothing

main =
  case lastElement [1,2,3,4] of
    Just a -> text (toString a)
    Nothing -> text "No element found"

預期結果

[編輯 | 編輯原始碼]
4

解決方案

華夏公益教科書