{- |

Module      : MyTake
Description : Implement take
Copyright   : © Frank Jung, 2022
License     : GPL-3

-}

module MyTake (myTake) where

-- | My version of take.
-- This does not check for negative numbers.
--
-- >>> myTake 1 "abc"
-- "a"
myTake :: Int -> [a] -> [a]
myTake :: forall a. Int -> [a] -> [a]
myTake Int
n [a]
_      | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = []
myTake Int
_ []              = []
myTake Int
n (a
x:[a]
xs)          = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
myTake (Int -> Int
forall a. Enum a => a -> a
pred Int
n) [a]
xs