title: Comparing wrapper object of generic type to with everything that is comparable to inner type?
body: <p>I am trying to build a wrapper around data saved in a redis database.
  What I want to do is access it as normal as possible as if I have a scala value of some type.
  It works, except for comparing it to anything (with <code>==</code> or similar).<br>
  <strong>So I want to be able to compare it to objects of the inner type.</strong></p>
  
  <p>Best I'll give example code first. This is a rough abstraction of my wrapper:</p>
  
  <pre><code>case class RedisObjectValue[T](name: String, default: T) {
    def :=(value: T): Boolean = {
      redisMagic.set(name, value)
    }
  
    def get: T = {
      redisMagic.get[T](name).getOrElse(default)
    }
  
    override def equals(o: Any) = o match {
      case ov: RedisObjectValue[T] =&gt;
        if (this.hashCode() == ov.hashCode()) true // Same reference
        else this.get == ov.get
      case v =&gt;
        // If we don't compare to another RedisObjectValue, let the equals method of data type handle it
        this.get.equals(v)
    }
  }
  </code></pre>
  
  <p>I have an implicit conversion set up in the companion object so that I can use the wrapper wherever I would use the base type.</p>
  
  <pre><code>object RedisObjectValue {
    implicit def objectValueToValue[T](ov: RedisObjectValue[T]): T = {
      ov.get
    }
  }
  </code></pre>
  
  <p>So, as I said, everything works.<br>
  Except the comparing stuff. For that, let's say I have a class <code>Player</code> two values, <code>userId</code> and <code>name</code>.</p>
  
  <pre><code>class Player {
    val userId = RedisObjectValue("userId", 0)
    val name = RedisObjectValue("player", "Unknown")
  }
  </code></pre>
  
  <p>And now I have a list of players and want to filter to get all players with name "Unknown".</p>
  
  <pre><code>list.filter(_.name == "Unknown")
  </code></pre>
  
  <p>Which does not work. If I extend the filter filter call and write a function, it tells me in IntelliJ "Comparing unrelated types".<br>
  And yeah, I understand what it is telling me, but I want to solve that. I mean I can easily compare Long to Int and similar stuff, so there must be a way to make them comparable, right?</p>
  
  <p>In the code above I have even written the equals function which uses the comparison to the inner type, but it seems like it is not used.</p>
  
  <p>Of course, I can always call <code>.get</code> on the values, like <code>players.filter(_.name.get == "Unknown")</code>, but that's a bit dirty and I would love to avoid that.</p>
  
  <h1>EDIT: Found the real problem after some analysis</h1>
  
  <p>Old text still above for reading, I will explain the problem here now.<br>
  I have a snippet which shows what is not working: <a href="https://ideone.com/AmQrkH" rel="nofollow">https://ideone.com/AmQrkH</a></p>
  
  <p>The Problem: The <code>RedisObjectValue</code> is defined as <code>Long</code>. When I am comparing it now with</p>
  
  <pre><code>players.filter(_.userId == 2)
  </code></pre>
  
  <p>for example, it doesn't give any results, even if there are players with <code>userId</code> 2, or to be more exact: <code>2l</code>.</p>
  
  <p>For direct <code>Long</code> it's not a problem.</p>
  
  <pre><code>players.filter(_._id == 2)
  </code></pre>
  
  <p>is working.<br>
  So is there any fix for that, so that comparable instances of classes to <code>T</code> can also be compared to <code>RedisObjectValue[T]</code>, and not just <code>T</code> itself?</p>