def build_optional_patterns(predicates)
      return [[TYPE, predicates, VALUE]] unless
        predicates.is_a? Enumerable

      var1 = TYPE
      patterns = predicates.each_with_object([]) do |predicate, ps|
        var2 =
          (ps.count == predicates.size - 1) ? VALUE : "obj#{ps.count}".to_sym
        ps << [var1, predicate, var2]
        var1 = var2
      end
    end
def build_optional_patterns(predicates)
      return [[TYPE, predicates, VALUE]] unless
        predicates.is_a? Enumerable

      var1 = TYPE
      patterns = predicates.each_with_object([]) do |predicate, ps|
        var2 =
          (ps.count == predicates.size - 1) ? VALUE : "obj#{ps.count}".to_sym
        ps << [var1, predicate, var2]
        var1 = var2
      end
    end
Builds patterns matching a predicate or chain of predicates given,
 assigning an unbound variable to each set of matches and passing it to
 the next pattern.

 @param predicates [#to_uri, Array<#to_uri>] a predicate or list of
   predicates to build patterns against.

 @return [Array<Array<#to_term>>] An array of pattern arrays
 @see RDF::Query
 @see RDF::Query::Pattern