I've created a function m
such that
m "abc" "def" == "bcd"
and I would like to create another function that uses m
to generate the output ["bcd","efg","hia"]
when given the input ["abc","def","ghi"]
The definition of m
is
m :: [a] -> [a] -> [a]
m str1 str2 = (drop 1 str1) ++ (take 1 str2)
You can make use of zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
here where you take the entire list as first parameter, and tail (cycle l)
as second parameter (with l
the list):
combine :: [a] -> [a]
combine l = zipWith m l (tail (cycle l))
zipWith
will enumerate concurrently on both lists and each time call m
with an element of the first and the second list. For example:
Prelude> combine ["abc","def","ghi"]
["bcd","efg","hia"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With