6

I've seen this code in a PureScript program, what does <<< do?

pinkieLogic :: (Tuple Boolean GameObject) -> GameObject -> GameObject
pinkieLogic (Tuple jumpPressed hater) p =
  hated hater p
  (solidGround
   <<< gravity
   <<< velocity
   <<< jump jumpPressed
   <<< clearSound)
Andrea
  • 19,134
  • 4
  • 43
  • 65

1 Answers1

11

<<< is the right-to-left composition operator. It's equivalent to . in Haskell. It works like this:

(f <<< g) x = f (g x)

That is, if you have two functions1 and you put <<< between then, you'll get a new function that calls the first function with the result of calling the second function.

So, that code could be rewritten as follows:

pinkieLogic :: (Tuple Boolean GameObject) -> GameObject -> GameObject
pinkieLogic (Tuple jumpPressed hater) p =
  hated hater p
  (\x -> solidGround (gravity (velocity (jump jumpPressed (clearSound x)))))

[1] Unlike Haskell's . operator, <<< in PureScript also works on categories or semigroupoids.

Andrea
  • 19,134
  • 4
  • 43
  • 65