< 99 Elm Problems < Problem 16

Solution 1: Using List.foldr and List.indexedMap

dropEvery n list =
  let
    indexed = List.indexedMap (,) list
    maybeAdd (i, x) xs =
      if (i + 1) % n == 0 then xs else x :: xs        
  in
    List.foldr maybeAdd [] indexed
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.