I simply want to substract 1 from every list element in [1,2,3,4] like
map (-1) [1,2,3,4] -- does not work
map ((-)1) [1,2,3,4] -- gives [0,-1,-2,-3] which is "-listvalue" + 1
map (\x = x - 1) [1,2,3,4] -- what I want but so verbose
map (+ (-1)) [1,2,3,4] -- well :)
map (flip (-) 1) [1,2,3,4] -- I heard of flip before
(map . flip (-)) 1 [1,2,3,4] -- Kinda nice mapped substration composing thingy
map pred [1,2,3,4] -- OK cheated and won't help with -2
Do I miss a form which would be "correct" and / or what Mr. Haskell use?
You can use the subtract function instead
map (subtract 1) [1,2,3,4]
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