scala - Type mismatch during refactoring using Slick -


i have following piece of code i'd make dryer:

def createadmin(/* ... */): future[int] =   db.run {     {       (users returning users.map(_.id)) += account(0, /* ... */)     } flatmap { id =>       admins += admin(userid = id, /* ... */)     }   }  def createstandarduser(/* ... */): future[int] =   db.run {     {       (users returning users.map(_.id)) += account(0, /* ... */)     } flatmap { id =>       standardusers += standarduser(userid = id, /* ... */)     }   } 

that compiles fine. if consolidate 2 following:

def createuser(role: string)(/* ... */): future[int] =   db.run {     {       (users returning users.map(_.id)) += account(0, /* ... */)     } flatmap { id =>       role match {         case "admin" =>           admins += admin(userid = id, /* ... */)         case "standard" =>           standardusers += standarduser(userid = id, /* ... */)       }     }   } 

i following type mismatch error:

[error]  found   : long => slick.dbio.dbioaction[int,slick.dbio.nostream,nothing] [error]  required: long => slick.dbio.dbioaction[int,slick.dbio.nostream,e2] [error]       } flatmap { id => [error]                      ^ [error] 1 error found 

i can't seem figure out why. can illuminate me?

the compiler can't figure out used effect type correctly. workaround should able give specifiying types used, e.g. in flatmap operation,

flatmap[int, nostream, effect.write] { id =>  

in case.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -