Problem 3 Solutions

Solution 1

elementAt : List a -> Int -> Maybe a
elementAt xs n =
    List.drop (n - 1) xs |> List.head

Solution 2

elementAt list n = 
    case List.drop (n - 1) list of 
        [] -> 
            Nothing 

        y :: ys -> 
            Just y

Back to Problem 2

results matching ""

    No results matching ""