Quantcast

How to get the Ordering in condition

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to get the Ordering in condition

Lee hu
support I have the following code:


class MyClass[K, V](val elements: Seq[(K, V)] {
   
def myFunc() = {
       
if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   
}
}


I do not want constraint the K: Ordering, but how can I judge it by condition?



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Aw: [scala-user] How to get the Ordering in condition

Dennis Haupt-2
you will want tp pattern match (google it)
 
Gesendet: Mittwoch, 15. Februar 2017 um 07:53 Uhr
Von: "Lee hu" <[hidden email]>
An: scala-user <[hidden email]>
Betreff: [scala-user] How to get the Ordering in condition
support I have the following code:
 
 
class MyClass[K, V](val elements: Seq[(K, V)] {
   def myFunc() = {
       if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   }
}
 
 
I do not want constraint the K: Ordering, but how can I judge it by condition?
 
 
 

 

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Lee hu
Thanks ! But how can I using a pattern match for a type K?


在 2017年2月15日星期三 UTC+8下午3:00:05,Dennis Haupt写道:
you will want tp pattern match (google it)
 
Gesendet: Mittwoch, 15. Februar 2017 um 07:53 Uhr
Von: "Lee hu" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="9bGj5FNMCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">lih...@...>
An: scala-user <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="9bGj5FNMCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala...@...>
Betreff: [scala-user] How to get the Ordering in condition
support I have the following code:
 
 
class MyClass[K, V](val elements: Seq[(K, V)] {
   def myFunc() = {
       if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   }
}
 
 
I do not want constraint the K: Ordering, but how can I judge it by condition?
 
 
 

 

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="9bGj5FNMCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala-user+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Jasper-M
In reply to this post by Lee hu
It's also worth mentioning that you asked the same question on http://stackoverflow.com/questions/42242668/how-can-i-judge-the-class-implement-the-ordering-in-scala

Op woensdag 15 februari 2017 07:53:44 UTC+1 schreef Lee hu:
support I have the following code:


class MyClass[K, V](val elements: Seq[(K, V)] {
   
def myFunc() = {
       
if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   
}
}


I do not want constraint the K: Ordering, but how can I judge it by condition?



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Oliver Ruebenacker
In reply to this post by Lee hu

     Hello,

  Since K is normally erased before runtime, you need to capture the type of K. You can do this using TypeTags. A short way of writing this is using the TypeTag as a context bound like this:

import scala.reflect.runtime.universe.{TypeTag, typeOf}

class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
def myFunc(): Unit = {
if (typeOf[K] <:< typeOf[Ordering[K]]) {
???
} else {
???
}
}
     Best, Oliver

On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <[hidden email]> wrote:
support I have the following code:


class MyClass[K, V](val elements: Seq[(K, V)] {
   
def myFunc() = {
       
if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   
}
}


I do not want constraint the K: Ordering, but how can I judge it by condition?



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Jasper-M
I don't think there should be a subtype relationship between K and Ordered[K].

Op woensdag 15 februari 2017 17:34:21 UTC+1 schreef Oliver Ruebenacker:

     Hello,

  Since K is normally erased before runtime, you need to capture the type of K. You can do this using TypeTags. A short way of writing this is using the TypeTag as a context bound like this:

import scala.reflect.runtime.universe.{TypeTag, typeOf}

class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
def myFunc(): Unit = {
if (typeOf[K] <:< typeOf[Ordering[K]]) {
???
} else {
???
}
}
     Best, Oliver

On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="6HKjRqprCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">lih...@...> wrote:
support I have the following code:


class MyClass[K, V](val elements: Seq[(K, V)] {
   
def myFunc() = {
       
if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   
}
}


I do not want constraint the K: Ordering, but how can I judge it by condition?



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="6HKjRqprCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala-user+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, <a href="http://www.type2diabetesgenetics.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;">Diabetes Portal, <a href="http://www.broadinstitute.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;">Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Oliver Ruebenacker
What else?

On Wed, Feb 15, 2017 at 12:27 PM, Jasper-M <[hidden email]> wrote:
I don't think there should be a subtype relationship between K and Ordered[K].

Op woensdag 15 februari 2017 17:34:21 UTC+1 schreef Oliver Ruebenacker:

     Hello,

  Since K is normally erased before runtime, you need to capture the type of K. You can do this using TypeTags. A short way of writing this is using the TypeTag as a context bound like this:

import scala.reflect.runtime.universe.{TypeTag, typeOf}

class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
def myFunc(): Unit = {
if (typeOf[K] <:< typeOf[Ordering[K]]) {
???
} else {
???
}
}
     Best, Oliver

On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <[hidden email]> wrote:
support I have the following code:


class MyClass[K, V](val elements: Seq[(K, V)] {
   
def myFunc() = {
       
if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   
}
}


I do not want constraint the K: Ordering, but how can I judge it by condition?



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Jasper-M
Isn't Ordering a typeclass?

Op 15 feb. 2017 18:30 schreef "Oliver Ruebenacker" <[hidden email]>:
What else?

On Wed, Feb 15, 2017 at 12:27 PM, Jasper-M <[hidden email]> wrote:
I don't think there should be a subtype relationship between K and Ordered[K].

Op woensdag 15 februari 2017 17:34:21 UTC+1 schreef Oliver Ruebenacker:

     Hello,

  Since K is normally erased before runtime, you need to capture the type of K. You can do this using TypeTags. A short way of writing this is using the TypeTag as a context bound like this:

import scala.reflect.runtime.universe.{TypeTag, typeOf}

class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
def myFunc(): Unit = {
if (typeOf[K] <:< typeOf[Ordering[K]]) {
???
} else {
???
}
}
     Best, Oliver

On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <[hidden email]> wrote:
support I have the following code:


class MyClass[K, V](val elements: Seq[(K, V)] {
   
def myFunc() = {
       
if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   
}
}


I do not want constraint the K: Ordering, but how can I judge it by condition?



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]m.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Oliver Ruebenacker
Don't know. So how would the code look like? Ordering[_] instead of Ordering[K]?

On Wed, Feb 15, 2017 at 12:32 PM, Jasper Moeys <[hidden email]> wrote:
Isn't Ordering a typeclass?

Op 15 feb. 2017 18:30 schreef "Oliver Ruebenacker" <[hidden email]>:

What else?

On Wed, Feb 15, 2017 at 12:27 PM, Jasper-M <[hidden email]> wrote:
I don't think there should be a subtype relationship between K and Ordered[K].

Op woensdag 15 februari 2017 17:34:21 UTC+1 schreef Oliver Ruebenacker:

     Hello,

  Since K is normally erased before runtime, you need to capture the type of K. You can do this using TypeTags. A short way of writing this is using the TypeTag as a context bound like this:

import scala.reflect.runtime.universe.{TypeTag, typeOf}

class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
def myFunc(): Unit = {
if (typeOf[K] <:< typeOf[Ordering[K]]) {
???
} else {
???
}
}
     Best, Oliver

On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <[hidden email]> wrote:
support I have the following code:


class MyClass[K, V](val elements: Seq[(K, V)] {
   
def myFunc() = {
       
if (k is ordering) {
         something
       
} else {
         otherthing
       
}
   
}
}


I do not want constraint the K: Ordering, but how can I judge it by condition?



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]m.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute




--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Clint Gilbert-2
In reply to this post by Jasper-M
"k is ordering" in the original question makes it sound like the OP
wants to test whether k is a subtype of Ordering, but Ordering /is/ a
typeclass.

OP, can you clarify?

On 02/15/2017 12:32 PM, Jasper Moeys wrote:

> Isn't Ordering a typeclass?
>
> Op 15 feb. 2017 18:30 schreef "Oliver Ruebenacker" <[hidden email]
> <mailto:[hidden email]>>:
>
>     What else?
>
>     On Wed, Feb 15, 2017 at 12:27 PM, Jasper-M <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>         I don't think there should be a subtype relationship between K
>         and Ordered[K].
>
>         Op woensdag 15 februari 2017 17:34:21 UTC+1 schreef Oliver
>         Ruebenacker:
>
>
>                  Hello,
>
>               Since K is normally erased before runtime, you need to
>             capture the type of K. You can do this using TypeTags. A
>             short way of writing this is using the TypeTag as a context
>             bound like this:
>
>             import scala.reflect.runtime.universe.{TypeTag, typeOf}
>
>             class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
>               def myFunc(): Unit = {
>                 if (typeOf[K] <:< typeOf[Ordering[K]]) {
>                   ???
>             } else {
>                   ???
>             }
>               }
>
>                  Best, Oliver
>
>             On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <[hidden email]>
>             wrote:
>
>                 support I have the following code:
>
>
>                 |
>                 classMyClass[K,V](val elements:Seq[(K,V)]{
>                    defmyFunc()={
>                        if(k isordering){
>                          something
>                        }else{
>                          otherthing
>                        }
>                    }
>                 }
>                 |
>
>
>                 I do not want constraint the K: Ordering, but how can I
>                 judge it by condition?
>
>
>
>                 --
>                 You received this message because you are subscribed to
>                 the Google Groups "scala-user" group.
>                 To unsubscribe from this group and stop receiving emails
>                 from it, send an email to [hidden email].
>                 For more options, visit
>                 https://groups.google.com/d/optout
>                 <https://groups.google.com/d/optout>.
>
>
>
>
>             --
>             Oliver Ruebenacker
>             Senior Software Engineer, Diabetes Portal
>             <http://www.type2diabetesgenetics.org/>, Broad Institute
>             <http://www.broadinstitute.org/>
>
>         --
>         You received this message because you are subscribed to the
>         Google Groups "scala-user" group.
>         To unsubscribe from this group and stop receiving emails from
>         it, send an email to [hidden email]
>         <mailto:[hidden email]>.
>         For more options, visit https://groups.google.com/d/optout
>         <https://groups.google.com/d/optout>.
>
>
>
>
>     --
>     Oliver Ruebenacker
>     Senior Software Engineer, Diabetes Portal
>     <http://www.type2diabetesgenetics.org/>, Broad Institute
>     <http://www.broadinstitute.org/>
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [hidden email]
> <mailto:[hidden email]>.
> For more options, visit https://groups.google.com/d/optout.
--



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Jasper-M
Anyway, I think the 2 possible answers have already been given on stackoverflow: 1) refactor into separate functions or 2) use an Optional typeclass.

Op woensdag 15 februari 2017 19:19:53 UTC+1 schreef Clint Gilbert:
"k is ordering" in the original question makes it sound like the OP
wants to test whether k is a subtype of Ordering, but Ordering /is/ a
typeclass.

OP, can you clarify?

On 02/15/2017 12:32 PM, Jasper Moeys wrote:

> Isn't Ordering a typeclass?
>
> Op 15 feb. 2017 18:30 schreef "Oliver Ruebenacker" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">cur...@...
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">cur...@...>>:
>
>     What else?
>
>     On Wed, Feb 15, 2017 at 12:27 PM, Jasper-M <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jaspe...@...
>     <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jaspe...@...>> wrote:
>
>         I don't think there should be a subtype relationship between K
>         and Ordered[K].
>
>         Op woensdag 15 februari 2017 17:34:21 UTC+1 schreef Oliver
>         Ruebenacker:
>
>
>                  Hello,
>
>               Since K is normally erased before runtime, you need to
>             capture the type of K. You can do this using TypeTags. A
>             short way of writing this is using the TypeTag as a context
>             bound like this:
>
>             import scala.reflect.runtime.universe.{TypeTag, typeOf}
>
>             class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
>               def myFunc(): Unit = {
>                 if (typeOf[K] <:< typeOf[Ordering[K]]) {
>                   ???
>             } else {
>                   ???
>             }
>               }
>
>                  Best, Oliver
>
>             On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <[hidden email]>
>             wrote:
>
>                 support I have the following code:
>
>
>                 |
>                 classMyClass[K,V](val elements:Seq[(K,V)]{
>                    defmyFunc()={
>                        if(k isordering){
>                          something
>                        }else{
>                          otherthing
>                        }
>                    }
>                 }
>                 |
>
>
>                 I do not want constraint the K: Ordering, but how can I
>                 judge it by condition?
>
>
>
>                 --
>                 You received this message because you are subscribed to
>                 the Google Groups "scala-user" group.
>                 To unsubscribe from this group and stop receiving emails
>                 from it, send an email to scala-user+...@googlegroups.com.
>                 For more options, visit
>                 <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout
>                 <<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout>.
>
>
>
>
>             --
>             Oliver Ruebenacker
>             Senior Software Engineer, Diabetes Portal
>             <<a href="http://www.type2diabetesgenetics.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;">http://www.type2diabetesgenetics.org/>, Broad Institute
>             <<a href="http://www.broadinstitute.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;">http://www.broadinstitute.org/>
>
>         --
>         You received this message because you are subscribed to the
>         Google Groups "scala-user" group.
>         To unsubscribe from this group and stop receiving emails from
>         it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala-user+...@googlegroups.com
>         <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala-user+unsubscribe@...>.
>         For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout
>         <<a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout>.
>
>
>
>
>     --
>     Oliver Ruebenacker
>     Senior Software Engineer, Diabetes Portal
>     <<a href="http://www.type2diabetesgenetics.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;">http://www.type2diabetesgenetics.org/>, Broad Institute
>     <<a href="http://www.broadinstitute.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;">http://www.broadinstitute.org/>
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala-user+...@googlegroups.com
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fWgclmxxCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">scala-user+unsubscribe@...>.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the Ordering in condition

Lee hu
Thanks for your answer! Because the gmail do not notify me well, I did not get all these reply.

your answer is really helpful in Stackoverflow! 




在 2017年2月16日星期四 UTC+8上午2:55:41,Jasper-M写道:
Anyway, I think the 2 possible answers have already been given on stackoverflow: 1) refactor into separate functions or 2) use an Optional typeclass.

Op woensdag 15 februari 2017 19:19:53 UTC+1 schreef Clint Gilbert:
"k is ordering" in the original question makes it sound like the OP
wants to test whether k is a subtype of Ordering, but Ordering /is/ a
typeclass.

OP, can you clarify?

On 02/15/2017 12:32 PM, Jasper Moeys wrote:

> Isn't Ordering a typeclass?
>
> Op 15 feb. 2017 18:30 schreef "Oliver Ruebenacker" <[hidden email]
> <mailto:[hidden email]>>:
>
>     What else?
>
>     On Wed, Feb 15, 2017 at 12:27 PM, Jasper-M <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>         I don't think there should be a subtype relationship between K
>         and Ordered[K].
>
>         Op woensdag 15 februari 2017 17:34:21 UTC+1 schreef Oliver
>         Ruebenacker:
>
>
>                  Hello,
>
>               Since K is normally erased before runtime, you need to
>             capture the type of K. You can do this using TypeTags. A
>             short way of writing this is using the TypeTag as a context
>             bound like this:
>
>             import scala.reflect.runtime.universe.{TypeTag, typeOf}
>
>             class MyClass[K: TypeTag, V](val elements: Seq[(K, V)]) {
>               def myFunc(): Unit = {
>                 if (typeOf[K] <:< typeOf[Ordering[K]]) {
>                   ???
>             } else {
>                   ???
>             }
>               }
>
>                  Best, Oliver
>
>             On Wed, Feb 15, 2017 at 1:53 AM, Lee hu <[hidden email]>
>             wrote:
>
>                 support I have the following code:
>
>
>                 |
>                 classMyClass[K,V](val elements:Seq[(K,V)]{
>                    defmyFunc()={
>                        if(k isordering){
>                          something
>                        }else{
>                          otherthing
>                        }
>                    }
>                 }
>                 |
>
>
>                 I do not want constraint the K: Ordering, but how can I
>                 judge it by condition?
>
>
>
>                 --
>                 You received this message because you are subscribed to
>                 the Google Groups "scala-user" group.
>                 To unsubscribe from this group and stop receiving emails
>                 from it, send an email to scala-user+...@googlegroups.com.
>                 For more options, visit
>                 <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout
>                 <<a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout>.
>
>
>
>
>             --
>             Oliver Ruebenacker
>             Senior Software Engineer, Diabetes Portal
>             <<a href="http://www.type2diabetesgenetics.org/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;">http://www.type2diabetesgenetics.org/>, Broad Institute
>             <<a href="http://www.broadinstitute.org/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;">http://www.broadinstitute.org/>
>
>         --
>         You received this message because you are subscribed to the
>         Google Groups "scala-user" group.
>         To unsubscribe from this group and stop receiving emails from
>         it, send an email to scala-user+...@googlegroups.com
>         <mailto:scala-user+[hidden email]>.
>         For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout
>         <<a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout>.
>
>
>
>
>     --
>     Oliver Ruebenacker
>     Senior Software Engineer, Diabetes Portal
>     <<a href="http://www.type2diabetesgenetics.org/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.type2diabetesgenetics.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVE8xTGqlzANyuan2sVDo75uy-vA&#39;;return true;">http://www.type2diabetesgenetics.org/>, Broad Institute
>     <<a href="http://www.broadinstitute.org/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.broadinstitute.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHloBLjHUP5Yhb6LyVOZ-JE5b4Y5A&#39;;return true;">http://www.broadinstitute.org/>
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scala-user+...@googlegroups.com
> <mailto:scala-user+[hidden email]>.
> For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...