implementing Monadic Composition in Cats Library for Scala 2.13.6
I need help solving I'm sure I'm missing something obvious here, but I'm working with difficulties composing monads using the Cats library in Scala 2.13.6... Specifically, I want to sequence a list of computations that return an `Option` but I keep working with a `None` when one of the computations fails. Here's a simplified version of what I'm trying to achieve: ```scala import cats.implicits._ def computation1: Option[Int] = Some(5) def computation2: Option[Int] = None // Simulating a failure def computation3: Option[Int] = Some(10) val computations = List(computation1, computation2, computation3) val result: Option[List[Int]] = computations.sequence ``` I expected the result to return `None` because of the second computation failing, but I was under the impression that `sequence` should handle this gracefully. Instead, I'm getting `Some(List())`. I’ve tried using `traverse` as well, thinking it would yield the same result, but I encountered the same scenario. Here's what I tried to troubleshoot the scenario: 1. Ensured that I'm importing the right implicits by including `import cats.implicits._`. 2. I also attempted to use `map` and `flatMap` manually on the list to debug the flow of data. What am I missing here? How can I properly sequence these computations so that if any of them return `None`, the entire result should reflect that failure? Am I misunderstanding how monadic composition should work in this context? Would using `Either` instead of `Option` be a better approach? Any insights would be greatly appreciated! For context: I'm using Scala on macOS. Has anyone else encountered this? What's the correct way to implement this?