Question

Just ran into this sample code learning about Commands in Scalatra:

 protected def handle: Handler  = {
    case c: CreateTodoCommand => 
      add(newTodo(~c.name.value))
  }

In this particular case, what exactly is the relevance of ~ in ~c.name.value? Not sure where to find more documentation on this particular symbol.

Was it helpful?

Solution

In Scala:

~x

translates to

x.unary_~

(this also applies to +,- and ! as explained in this post). So your example translates to:

add(newTodo(c.name.value.unary_~))

The documentation can hence be found at the type of value.

OTHER TIPS

it seems to be related to the block of code commented out in here: https://github.com/scalatra/scalatra/blob/2.2.x_2.9/core/src/main/scala/org/scalatra/package.scala

that is the only unary tilde operator if found that could be working here. the others seem to mainly be bitwise not operators

It actually seems that this might also be some import from scalaz library, tho the import statements are missing. similar uses of ~Option[_] can be found elsewhere as well...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top