Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top