0

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: _*)
        }

1 Answer 1

3

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.

3
  • Thank you for your answer. It now compiles with fragments.or(NonEmptyList.fromListUnsafe(filterFragments). However the end result is now diffrent. Ie actual: 'Fragment("( ((collections.end_date is null AND collections.start_date <= ? ) OR (collections.end_date >= ? AND collections.start_date <= ?)) OR collections.start_date > ? ) ")' did not equal expected: 'Fragment("( ((collections.end_date is null AND collections.start_date <= ? ) OR (collections.end_date >= ? AND collections.start_date <= ?)) ) OR ( collections.start_date > ? ) ")' Commented Jul 7, 2023 at 14:34
  • If you read the release notes I linked, they mention "when calling methods like and/or, we now wrap the resulting expression in parenthesis." Looks like the collections.start_date > ? clause got subjected to that.
    – Dylan
    Commented Jul 7, 2023 at 15:32
  • 1
    Note: I'm not a Doobie developer so I can't really comment in detail about their intentions. If you disagree with the new behavior of the method, you should open an issue
    – Dylan
    Commented Jul 7, 2023 at 15:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.