Basically, I have a list ["apple", "banana"]
and I want to append "|4"
to each argument in the list, so that I end up with ["apple|4", "banana|4"]
.
I can do map (Text.append "|4") ["apple", "banana"]
, but that appends in the wrong order, i.e. the result is ["|4apple", "|4banana"]
.
Is there a good way to tell Text.append
to go in the other direction in this map?
CodePudding user response:
There are a couple ways to do this. One way is to use flip
:
map (flip Text.append "|4") ["apple", "banana"]
You could also explicitly use a lambda:
map (\t -> Text.append t "|4") ["apple", "banana"]
Or use the backtick infix operator syntax:
map (`Text.append` "|4") ["apple", "banana"]
CodePudding user response:
Oh actually I think something like:
[Text.append x "|4" | x <- ["apple", "banana"]]
(Posting in case this is useful for anyone in the future).