Git Product home page Git Product logo

ghosts's Introduction

Ghosts

Nano library that provides syntax niceties on top of cats

Rationale

Let's say you have val v: F[Either[A, B]] where F is some monad and you want to convert Either inside F. You have following options:

  • Use nested map calls:

    v.map(_.map(f))

    Pros:

    • Pretty straightforward
    • Type of outer monad doesn't change - it's still F

    Cons:

    • Code become clattered with multiple map/flatMap calls
  • Use EitherT:

    import cats.data.EitherT
        
    EitherT(v).map(f).value

    Pros:

    • Allows you to use it in for-comprehension

    Cons:

    • Type of outer monad changes - now it's EitherT instead of F and you can't directly pass your value to function that expects `F'.
    • Increased depth of monad's stack makes code harder to read
    • Code is clattered with EitherT's contructor calls
  • Use this library:

    import ghosts.either._
        
    v.mapT(f)

    Pros:

    • Type of outer monad doesn't change: all methods of F are directly available to you, you can freely pass it to any fuction that expects F.
    • Depth of monad stack stays the same

    Cons:

    • Not suitable for use inside for-comprehension

How to use

Add the following to your build.sbt file: libraryDependencies += "com.github.mkulak" %% "ghosts" % "0.0.1"

List of Dependencies

org.typelevel" %% "cats" % "0.8.1"

ghosts's People

Contributors

mkulak avatar

Watchers

 avatar

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.