Hi,
I am quite new to PureScript. Having explored its features, is is possible to use function argument placeholders _
to switch up the order, e.g. similiar to _
placeholders already used with Records?
Example:
myop1 :: String -> String -> String
myop1 s1 s2 = s1 <> s2
To fix second instead of first argument (via usual partial application) in myop1
I can do:
(_ `myop1` "foo" ) <$> ["a","b","c"]
flip myop1 "foo" <$> ["a","b","c"]
, both resulting in ["afoo","bfoo","cfoo"]
.
Is is somehow possible to use the following?
(myop1 _ "foo" ) <$> ["a","b","c"]
More apparent with > 2 args, is there a more elegant way than this:
myop2 :: Int -> Int -> Int -> Int
myop2 x times minus = x * times - minus
(\n -> myop2 n 4 2) <$> [1,2,3] -- [2,6,10]
, such as
(myop2 _ 4 2) <$> [1,2,3]
?
Full test code:
module Main where
import Prelude
import Effect (Effect)
import Effect.Console (log)
main :: Effect Unit
main = do
log ( (_ `myop1` "foo" ) <$> ["a","b","c"] # show )
log ( flip myop1 "foo" <$> ["a","b","c"] # show )
log ( (\n -> myop2 n 4 2) <$> [1,2,3] # show )
myop2 :: Int -> Int -> Int -> Int
myop2 x times minus = x * times - minus
myop1 :: String -> String -> String
myop1 s1 s2 = s1 <> s2