@@ -86,9 +86,6 @@ package object db {
8686 def fold [B ](ra : Failures ⇒ B , rb : A ⇒ B )(implicit F : Monad [F ]): FoxyT [F , B ] = // TODO: this is not fold… Find a better name or remove it? @michalrus
8787 fa.map(rb).handleError(ra)
8888
89- def meh (implicit M : Monad [F ]): FoxyT [F , Unit ] =
90- fa.void // TODO: remove me? But it’s cute… @michalrus
91-
9289 def failuresToWarnings (valueIfWasFailed : A )(pf : PartialFunction [Failure , Boolean ])(
9390 implicit F : Monad [F ]): FoxyT [F , A ] =
9491 fa.handleErrorWith { fs ⇒
@@ -105,15 +102,6 @@ package object db {
105102 }
106103
107104 trait FoxyTFunctions [F [_]] {
108- def good [A ](a : A )(implicit F : Monad [F ]): FoxyT [F , A ] = // TODO: remove me @michalrus
109- a.pure[FoxyT [F , ? ]]
110-
111- def unit (implicit F : Monad [F ]): FoxyT [F , Unit ] =
112- ().pure[FoxyT [F , ? ]] // TODO: remove me? @michalrus
113-
114- def none [A ](implicit F : Monad [F ]): FoxyT [F , Option [A ]] =
115- (None : Option [A ]).pure[FoxyT [F , ? ]] // TODO: remove me? @michalrus
116-
117105 def uiWarning (f : Failure )(implicit F : Monad [F ]): FoxyT [F , Unit ] =
118106 StateT .modify(MetaResponse .Warning (f) :: _)
119107
@@ -149,6 +137,8 @@ package object db {
149137 case _ ⇒ EitherT .right(F .pure((s, ())))
150138 })
151139
140+ // TODO: maybe move the quasi-`sequence`-s from Functions to Ops? @michalrus
141+
152142 /** Just like ``sequence`` but—in case of a failure—unlawful, as it will join failures from all Foxies. */
153143 def seqCollectFailures [L [_], A ](lfa : L [FoxyT [F , A ]])(implicit L : TraverseFilter [L ],
154144 F : Monad [F ]): FoxyT [F , L [A ]] =
@@ -270,32 +260,40 @@ package object db {
270260 def appendForUpdate [A , B <: slick.dbio.NoStream ](sql : SqlAction [A , B , Effect .Read ]): DBIO [A ] =
271261 sql.overrideStatements(sql.statements.map(_ + " for update" ))
272262
273- // TODO: I don’t know… does this help ? @michalrus
263+ // TODO: Is this more readable than inlining ? @michalrus
274264 def ifElse [A ](condition : Boolean , ifBranch : ⇒ DbResultT [A ], elseBranch : ⇒ DbResultT [A ]) =
275265 if (condition) ifBranch else elseBranch
276266
277- def when [F [_]](p : Boolean , s : ⇒ F [Unit ])( implicit F : Applicative [ F ]): F [Unit ] =
278- if (p) s.void else F .pure(())
267+ def when [F [_]: Applicative ](p : Boolean , s : ⇒ F [Unit ]): F [Unit ] =
268+ if (p) s else ().pure[ F ]
279269
280- def doOrGood [A ](condition : Boolean , action : ⇒ DbResultT [A ], good : ⇒ A )(implicit ec : EC ): DbResultT [A ] =
281- if (condition) action else DbResultT .good(good)
270+ // TODO: Is this more readable than inlining? @michalrus
271+ def doOrGood [F [_]: Applicative , A ](p : Boolean , action : ⇒ F [A ], good : ⇒ A )(implicit ec : EC ): F [A ] =
272+ if (p) action else good.pure[F ]
282273
283- def doOrFail [A ](condition : Boolean , action : ⇒ DbResultT [A ], failure : ⇒ Failure )(
284- implicit ec : EC ): DbResultT [A ] =
285- if (condition) action else DbResultT .failure(failure)
274+ // TODO: Is this more readable than inlining? @michalrus
275+ def doOrFail [F [_]: Monad , A ](p : Boolean , action : ⇒ FoxyT [F , A ], failure : ⇒ Failure )(
276+ implicit ec : EC ): FoxyT [F , A ] =
277+ if (p) action else FoxyT [F ].failure(failure)
286278
279+ // TODO: Is this more readable than inlining? @michalrus
280+ // FIXME: should be defined over FoxyT, but inference fails then… @michalrus
287281 def failIf (condition : Boolean , failure : ⇒ Failure )(implicit ec : EC ): DbResultT [Unit ] =
288- if (condition) DbResultT .failure(failure) else DbResultT .unit
282+ if (condition) DbResultT .failure(failure) else ().pure[ DbResultT ]
289283
284+ // TODO: Is this more readable than inlining? @michalrus
285+ // FIXME: should be defined over FoxyT, but inference fails then… @michalrus
290286 def failIfNot (condition : Boolean , failure : ⇒ Failure )(implicit ec : EC ): DbResultT [Unit ] =
291287 failIf(! condition, failure)
292288
293- def failIfFailures (failures : Seq [Failure ])(implicit ec : EC ): DbResultT [Unit ] =
289+ // TODO: Is this more readable than inlining? @michalrus
290+ // TODO: There’s only one usage in the whole codebase. @michalrus
291+ def failIfFailures [F [_]: Monad ](failures : Seq [Failure ]): FoxyT [F , Unit ] =
294292 failures match {
295293 case head :: tail ⇒
296- DbResultT .failures(NonEmptyList .of(head, tail : _* ))
294+ FoxyT [ F ] .failures(NonEmptyList .of(head, tail : _* ))
297295 case _ ⇒
298- DbResultT .unit
296+ ().pure[ FoxyT [ F , ? ]]
299297 }
300298
301299 implicit class EnrichedSQLActionBuilder (val action : SQLActionBuilder ) extends AnyVal {
@@ -329,33 +327,32 @@ package object db {
329327
330328 def findOrCreate (r : DbResultT [R ])(implicit ec : EC ): DbResultT [R ] =
331329 dbio.dbresult.flatMap {
332- case Some (model) ⇒ DbResultT .good( model)
330+ case Some (model) ⇒ model.pure[ DbResultT ]
333331 case None ⇒ r
334332 }
335333
336334 // Last item in tuple determines if cart was created or not
337335 def findOrCreateExtended (r : DbResultT [R ])(implicit ec : EC ): DbResultT [(R , FoundOrCreated )] =
338336 dbio.dbresult.flatMap {
339- case Some (model) ⇒ DbResultT .good(( model, Found ))
337+ case Some (model) ⇒ ( model, Found : FoundOrCreated ).pure[ DbResultT ]
340338 case _ ⇒ r.map(result ⇒ (result, Created ))
341339 }
342340
343341 def mustFindOr (notFoundFailure : Failure )(implicit ec : EC ): DbResultT [R ] =
344342 dbio.dbresult.flatMap {
345- case Some (model) ⇒ DbResultT .good( model)
343+ case Some (model) ⇒ model.pure[ DbResultT ]
346344 case None ⇒ DbResultT .failure(notFoundFailure)
347345 }
348346
349347 def mustNotFindOr (shouldNotBeHere : Failure )(implicit ec : EC ): DbResultT [Unit ] =
350348 dbio.dbresult.flatMap {
351- case None ⇒ DbResultT .unit
349+ case None ⇒ ().pure[ DbResultT ]
352350 case Some (_) ⇒ DbResultT .failure(shouldNotBeHere)
353351 }
354352
355- // we only use this when we *know* we can call head safely on a query. (e.g., you've created a record which
353+ // we only use this when we *know* we can call head unsafely on a query. (e.g., you've created a record which
356354 // has a FK constraint to another table and you then fetch that associated record -- we already *know* it must
357355 // exist.
358- // FIXME: if you know it, prove it. Or s/safe/unsafe/ in the name *AND* comment. @michalrus
359- def safeGet (implicit ec : EC ): DBIO [R ] = dbio.map(_.get)
356+ def unsafeGet (implicit ec : EC ): DBIO [R ] = dbio.map(_.get)
360357 }
361358}
0 commit comments