Value of the last element of a list

前端 未结 10 992
小蘑菇
小蘑菇 2020-12-18 18:55

how to get the value of the last element of a List? I\'ve noted that List.hd (or .Head) return an item, while List.tl (or .Tail) returns a List.

Is rev the List and

10条回答
  •  忘掉有多难
    2020-12-18 19:24

    As a novice F# developer, I don't see what the harm is in doing the following

    let mylist = [1;2;3;4;5]
    
    let lastValue = mylist.[mylist.Length - 1]
    

    Imperative in nature? Yes but no need for recursion.

提交回复
热议问题