我读了这个。 How can you configure python outline mode in VS Code to show only classes and methods
但是VS Code 1.40.0尚不能做到。 Spyder几乎可以做,但是我想使用VS Code。 我只想做一个。
我能以某种方式使VS Code显示
import cats.Monad
import cats.data.EitherT
import cats.effect.{IO,Sync}
import cats.implicits._
case class User(nick: String,points: Int)
trait UserRepositoryAlg[F[_]] {
def find(nick: String): F[Either[Error,User]]
def update(user: User): F[Either[Error,User]]
}
//UserRepositoryInterpreter is parametrized,but we require that F has typeclass Sync,//which would allow us to delay effects with `Sync[F].delay`.
//Sync extends Monad,so we don't need to request is explicitly to be able to use for-comprehension
class UserRepositoryInterpreter[F[_]: Sync] extends UserRepositoryAlg[F] {
val users: mutable.ListBuffer[User] = ListBuffer()
override def find(nick: String): F[Either[Error,User]] = for {
//Finding user will be delayed,until we interpret and run our program. Delaying execution is useful for side-effecting effects,//like requesting data from database,writting to console etc.
res <- Sync[F].delay(Either.fromOption(users.find(user => user.nick == nick),new Error("Couldn't find user")))
} yield res
//we can reuse find method from UserRepositoryInterpreter,but we have to wrap find in EitherT to access returned user
override def update(user: User): F[Either[Error,User]] = (for {
found <- EitherT(find(user.nick))
updated = found.copy(points = found.points + user.points)
} yield updated).value
}
object Main extends App {
class Pointer[F[_] : Monad](repo: UserRepositoryAlg[F]) {
def addPoints(nick: String): EitherT[F,Error,User] = {
for {
user <- EitherT(repo.find(nick))
updated <- EitherT(repo.update(user))
} yield updated
}
}
//at this point we define,that we want to use IO as our effect monad
val pointer = new Pointer[IO](new UserRepositoryInterpreter[IO]).addPoints("nick")
pointer.value.unsafeRunSync() //at the end of the world we run our program
}
为
# %% Top hierarchy
def abc():
# %% Top hierarchy
def xyz():
在轮廓上?
还是应该等待下一个版本?