Search code examples
scalascala-catsdoobie

Doobie upgrade from 1.0.0-RC2 to 1.0.0-RC4 causes fragments.or not to compile


My code (below) is failing to compile after a Doobie library upgrade. fragments.or(filterFragments: _*) "Cannot resolve overloaded method 'or'". Presumably the signature has changed but I cant get it work in the same as it did before the upgrade. Am I missing something?

 def statusFilter(queryCriteria: QueryCriteria): Option[Fragment] =
        queryCriteria.statusFilter.map { filters =>
          val filterFragments: List[Fragment] = filters.map {
            case StatusFilter(Open, date)     => statusFilterOpen(date)
            case StatusFilter(Upcoming, date) => statusFilterUpcoming(date)
            case StatusFilter(Closed, date)   => statusFilterClosed(date)
            case _                            => fr""
          }.toList
          fragments.or(filterFragments: _*)
        }

Solution

  • In RC2 the method is

    def or(fs: doobie.Fragment*): doobie.Fragment 
    

    but In RC4 that signature was removed and replaced with two different overloads:

    def or[F[_]](fs: F[doobie.Fragment], withParen: Boolean = true)
      (implicit arg0: Reducible[F]): doobie.Fragment
    
    
    def or(f1: doobie.Fragment, f2: doobie.Fragment, fs: doobie.Fragment*)
      : doobie.Fragment 
    

    The RC3 Release Notes mention "Improved composability and safety of fragment helpers (doobie.util.fragments.*)"

    Seems like the goal was to prevent passing zero fragments to the or method. If you can construct a cats.NonEmptyList[Fragment], you should be able to pass that directly to the first version that expects an F[Fragment] without a :_* signal, since NonEmptyList has a Reducible instance. List does not have a Reducible since that typeclass comes with the expectation of the collection being non-empty.