Skip to content

Instantly share code, notes, and snippets.

@nfunato
Created December 28, 2013 06:04
Show Gist options
  • Select an option

  • Save nfunato/8156534 to your computer and use it in GitHub Desktop.

Select an option

Save nfunato/8156534 to your computer and use it in GitHub Desktop.
-- O(n) revTake and revDrop using list-numeral alike Church-numeral
-- (from Richard O'Keefe's post to haskell-cafe, i.e.
-- http://www.haskell.org/pipermail/haskell-cafe/2010-September/083905.html)
-- | l |
-- +----------------+-----+
-- | l-n (_:m) n |
revTake n xs = drop' (drop n xs) xs
where drop' (_:m) (_:xs) = drop' m xs
drop' _ xs = xs
revDrop n xs = take' (drop n xs) xs
where take' (_:m) (x:xs) = x : take' m xs
take' _ _ = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment