title: Can't figure out syntax in scala compose function
body: <p>I am working through the red book and when checking my answers for the exercises , I found that the solution for one of the exercises (6.11) was quite different (and much more elegant and cryptic than my own solution).</p>
  <p>Here is the code:</p>
  <pre class="lang-scala prettyprint-override"><code>object Candy {
    def update: Input =&gt; Machine =&gt; Machine = (i: Input) =&gt; (s: Machine) =&gt;
      (i, s) match {
        case (_, Machine(_, 0, _)) =&gt; s
        case (Coin, Machine(false, _, _)) =&gt; s
        case (Turn, Machine(true, _, _)) =&gt; s
        case (Coin, Machine(true, candy, coin)) =&gt;
          Machine(false, candy, coin + 1)
        case (Turn, Machine(false, candy, coin)) =&gt;
          Machine(true, candy - 1, coin)
      }
  
    def simulateMachine(inputs: List[Input]): State[Machine, (Int, Int)] = for {
      _ &lt;- State.sequence(inputs map (modify[Machine] _ compose update))
      s &lt;- get
    } yield (s.coins, s.candies)
  
    def modify[S](f: S =&gt; S): State[S, Unit] = for {
      s &lt;- get // Gets the current state and assigns it to `s`.
      _ &lt;- set(f(s)) // Sets the new state to `f` applied to `s`.
    } yield ()
  
    def get[S]: State[S, S] = State(s =&gt; (s, s))
  
    def set[S](s: S): State[S, Unit] = State(_ =&gt; ((), s))
  </code></pre>
  <p>The bit I am unsure of is this line:
  <code>inputs map (modify[Machine] _ compose update)</code></p>
  <p>I understand how compose works but this particular syntax is really throwing me for a loop. Is there a way that this can be rewritten that is not so compact that would help a noob understand?</p>
  <p>Thanks in advance.</p>
  <p>Also for anyone else trying to better understand how this code works, <a href="https://stackoverflow.com/questions/58587641/functional-programing-in-scala-exercise-6-11-how-does-this-for-comprehension-wo">this</a> post I found helpful.</p>