this is what I'm trying to do:
If I give
$hello world I would get world
What I am doing is this :
tail (unwords (words "$hello world"))
but I'm getting "hello world" instead of world
What do I have to do to get it right?
You have to apply unwords after tail, not the other way around.
The intended sequence of steps is (probably) as follows:
The way you do it, you split and immediately re-join the words and then you just drop the first character of the resulting string (since a String is just a list of Chars).
What you're wanting to do is
unwords $ tail $ words "$hello world"
Working through it in GHCi we get
> words "$hello world"
["$hello", "world"]
> tail $ words "$hello world"
["world"]
> unwords $ tail $ words "$hello world"
"world"
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