mirror of
https://github.com/Noratrieb/haskell-shit.git
synced 2026-01-14 11:45:03 +01:00
how
This commit is contained in:
parent
edfc994dcc
commit
500db55204
1 changed files with 27 additions and 0 deletions
27
src/Lib.hs
27
src/Lib.hs
|
|
@ -116,3 +116,30 @@ connect2Strings = connect []
|
||||||
connect w x y
|
connect w x y
|
||||||
| x `isPrefixOf` y = w ++ y
|
| x `isPrefixOf` y = w ++ y
|
||||||
| otherwise = connect (w ++ [head x]) (tail x) y
|
| otherwise = connect (w ++ [head x]) (tail x) y
|
||||||
|
|
||||||
|
nthElement :: Int -> [a] -> a
|
||||||
|
nthElement 0 (x : _) = x
|
||||||
|
nthElement n (_ : xs) = nthElement (n -1) xs
|
||||||
|
|
||||||
|
forEach :: (a -> IO ()) -> [a] -> IO ()
|
||||||
|
forEach f [x] = f x
|
||||||
|
forEach f (x:xs) = do
|
||||||
|
f x
|
||||||
|
forEach f xs
|
||||||
|
|
||||||
|
head2 :: [a] -> a
|
||||||
|
head2 [x] = x
|
||||||
|
head2 (x:_) = x
|
||||||
|
|
||||||
|
tail2 :: [a] -> [a]
|
||||||
|
tail2 (_:xs) = xs
|
||||||
|
|
||||||
|
last2 :: [a] -> a
|
||||||
|
last2 [x] = x
|
||||||
|
last2 (_:xs) = last2 xs
|
||||||
|
|
||||||
|
init2 :: [a] -> [a]
|
||||||
|
init2 [] = []
|
||||||
|
init2 [_] = []
|
||||||
|
init2 (x:xs) = x : init2 xs
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue