Find the nearest value in an Elm list

```
closest: Int -> List Int -> Int
closest size sizes =
  sizes
      |> List.sort
      |> List.filter (\s -> s < size)
      |> List.reverse
      |> List.head
      |> Maybe.withDefault 0
```

This example is not meant to be exhaustive nor performant.

Nick Ciolpan
20 Jul 2020
« Back to post