99 Elm Problems/Problem 16/Solutions

From Wikibooks, open books for an open world
Jump to navigation Jump to search

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