Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2014 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/10343924 to your computer and use it in GitHub Desktop.
Save anonymous/10343924 to your computer and use it in GitHub Desktop.
module Every where
import Control.Lens
-- |
--
-- >>> everyN 2 []
-- []
--
-- >>> everyN 2 [1]
-- []
--
-- >>> everyN 2 [1,2,3,4,5]
-- [2,4]
--
-- >>> everyN (-1) []
-- []
--
-- >>> everyN (-1) [1,2,3]
-- [1,2,3]
--
-- >>> everyN (-4) [1,2,3]
-- [1,2,3]
--
-- >>> everyN 4 [1..20]
-- [4,8,12,16,20]
--
-- prop> everyN 1 x == (x :: [Int])
--
-- prop> everyN n [] == []
everyN :: Int -> [a] -> [a]
everyN n x =
over _tail (everyN n) (snd (splitAt (pred n) x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment