What is โ† in Scala?

I googled "โ†" and searched here, unable to find anything. But I found this source code for a chess game. Check it out here . Example code block with abundant use of this symbol:

for { storedFen โ† GameRepo initialFen game fen = storedFen orElse (aiVariant match { case v@Horde => v.initialFen.some case _ => none }) uciMoves โ† uciMemo get game moveResult โ† move(uciMoves.toList, fen, level, aiVariant) uciMove โ† (UciMove(moveResult.move) toValid s"${game.id} wrong bestmove: $moveResult").future result โ† game.toChess(uciMove.orig, uciMove.dest, uciMove.promotion).future (c, move) = result progress = game.update(c, move) _ โ† (GameRepo save progress) >>- uciMemo.add(game, uciMove.uci) } yield PlayResult(progress, move) 
+7
source share
4 answers

The Scala specification says on page 4 that โ† (unicode \u2190 ) is reserved, as is its equivalent to ascii <- which, as others point out, is an iterator for the for loop.

 for(x <- 1 to 5) println(i) 

In scala, you can enclose a complex expression and treat it as one line with the value indicated at the end of the expression. This makes it possible to create a large nested for loop in which each loop loop increments the iterator at the end of the loop until iterates over the earlier iterator.

Here is an example using the scala shell and both syntaxes:

This is how most people write for the loop

Please note that | character is a line continuation, not typed by me, but inserted into the scala shell

 scala> for { | x<-1 to 5 | y<-2 to 6 | } println (x,y) (1,2) (1,3) (1,4) (1,5) (1,6) (2,2) (2,3) ... (5,5) (5,6) 

But you can also use this funny Unicode arrow character, and it does the same:

 scala> for { | x โ† 1 to 5 | y โ† 2 to 6 | } println (x,y) (1,2) (1,3) (1,4) (1,5) (1,6) (2,2) (2,3) ... (5,5) (5,6) 

You may notice that some of the expressions in this complex for {} block you posted are assignments, not iterations. This allows, and does not break the chain of iterations. Here is a simpler example:

 scala> for { | x โ† 1 to 3 | y = x*x | z โ† 1 to 4 | } println (x,y,z) (1,1,1) (1,1,2) (1,1,3) (1,1,4) (2,4,1) (2,4,2) (2,4,3) (2,4,4) (3,9,1) (3,9,2) (3,9,3) (3,9,4) 
+13
source

I am not a Scala programmer. But according to this Scala accepts the unicode character โ†, which is equivalent to the <- operator. You can turn "=>" into "โ‡’", "-" "into" โ†’ "and" <- "into" โ† ".

+2
source

This is the same as <- , which is commonly used in for expressions.

0
source

Please note that starting with Scala 2.13 version Scala 2.13 the โ† symbol is not recommended:

Obsolete unicode arrows โ‡’ , โ† and โ†’ # 7540 )

It used to be equivalent to <- .


The same goes for โ‡’ (equivalent => ) and โ†’ (equivalent -> ).

0
source

All Articles