Search code examples
scalascalatra

Tilde in Scala found in Scalatra example code


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.


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.