Coder Social home page Coder Social logo

Make documentation more usable about sealed-monad HOT 1 OPEN

luksow avatar luksow commented on July 27, 2024
Make documentation more usable

from sealed-monad.

Comments (1)

MateuszKubuszok avatar MateuszKubuszok commented on July 27, 2024

Things that were most surprising initially to me, which I would highlight:

  • there are 2 type params that describe some result type: Sealed[F, A, ADT] - A and ADT

    • A is an intermediate result type of sort
    • ADT is like a final result type
  • ADT is used for handling errors, HOWEVER it is also used as a final result type when exiting the Sealed monad in run - therefore while most of the time ADT can be used for some error-only type, on run ADT is expected to be something which stores both errors and success values

  • in a way it makes it similar to (a: L).tailRecM[R](... : L => F[Either[L, R]])'s parameters where L is intermediate result and R is final result

  • however when we are thinking that Sealed is similar to EitherT then we might be surprised because EitherT[F, L, R] flatMaps/maps etc on right R value, while Sealed[F, A, ADT] on left A value

    • to add to confusion method names are borrowed from EitherT
  • probably it would make more sense to use examples comparing it to Result<S, F> from Rust which has a success as the first and a failure as the second type parameter

  • it would also make sense to show that intended usages for ADT is something like

    enum UserCreationResult:
      case Success
      case UserAlreadyExists(details: String)
      case InvalidEmail(details: String)

    which models all allowed outcomes for some business action

    • since such enums are sealed traits in Scala 2 it explains the Sealed name, but I haven't been able to make that connection for a long time

All in all use cases are pretty reasonable BUT do not match Cats conventions and without a proper explanation Cats' users might follow wrong intuitions.

from sealed-monad.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.