How to type the right arrow (i.e., ⇒, not =>) in I

2019-08-21 11:39发布

问题:

A common symbol to use in Scala pattern matching is the right arrow, either ⇒ or =>. So my question is what is the shortcut to type the neat looking right arrow ⇒? I use IntelliJ on Mac OS.

below is an example code that uses ⇒ from https://doc.akka.io/docs/akka/current/guide/tutorial_1.html

package com.lightbend.akka.sample

import akka.actor.{ Actor, Props, ActorSystem }
import scala.io.StdIn

class PrintMyActorRefActor extends Actor {
  override def receive: Receive = {
    case "printit" ⇒
      val secondRef = context.actorOf(Props.empty, "second-actor")
      println(s"Second: $secondRef")
  }
}

object ActorHierarchyExperiments extends App {
  val system = ActorSystem("testSystem")

  val firstRef = system.actorOf(Props[PrintMyActorRefActor], "first-actor")
  println(s"First: $firstRef")
  firstRef ! "printit"

  println(">>> Press ENTER to exit <<<")
  try StdIn.readLine()
  finally system.terminate()
}

回答1:

Most projects that use this symbol, use a tool like Scalariform to automatically change => into after you've written it.

Personally though, I prefer to use a font with ligatures (such as Fira Code) to render nice arrows and such.



回答2:

In your Settings tab (File => Settings in Linux, probably the same/similar on Mac OS), add it as a Live Template through Editor => Live Templates.

See here for more info