Just adding to the other excellent answers. Scala offers two often criticized symbolic operators, /:
(foldLeft
) and :\
(foldRight
) operators, the first being right-associative. So the following three statements are the equivalent:
( 1 to 100 ).foldLeft( 0, _+_ )
( 1 to 100 )./:( 0 )( _+_ )
( 0 /: ( 1 to 100 ) )( _+_ )
As are these three:
( 1 to 100 ).foldRight( 0, _+_ )
( 1 to 100 ).:\( 0 )( _+_ )
( ( 1 to 100 ) :\ 0 )( _+_ )