Skip to content

A little helpers class using Cats EitherT to make better for comprehension

License

Notifications You must be signed in to change notification settings

haris44/for-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

For-helpers

Using Cats EitherT Monad to make Scala for/yield Great Again !

--

Add Cats on your dependencies

Copy and import forHelpers object (It uses implicits)

import cats.implicits._
import helpers.forHelpers._

Use for/yield with :

  • Option[A],
  • Future[Option[A]],
  • Future[Either[A,B]]
  • JsResult[A]

And play with for comprehension !

def insert = Action.async(bodyParser.json) {
    request => (for {
        json <- request.body.validate[Contact] |? BadRequest
        dao <- contactDao.add(json) |? InternalServerError
      } yield Created(Json.toJson(dao))).merge
  }

You can specify Result type on forHelpers

Have fun !

--

For-helpers is actually not on Maven Repository, you must copy/paste the helper class. But if you like and need (or prefer), I can make the repo on the day

About

A little helpers class using Cats EitherT to make better for comprehension

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published