Value of the last element of a list

前端 未结 10 954
小蘑菇
小蘑菇 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:07

    A more concise version based on Mitch's answer:

    let lastItem = myList |> List.rev |> List.head
    

    The myList list is sent to List.rev function. The result is then processed by List.head

提交回复
热议问题