Friday, December 5, 2008

Scala Operator Cheat Sheet

A list of the standard Scala operators.

Contents

Introduction

Scala syntax allows method names to use special characters such as +, * and :, and to use them as infix operators, which effectively allows operator overloading as well as the creation of new operators. This can make code more concise, but can also make it difficult to figure out what a particular Scala operator does, because you can't effectively do a Google search for \: or ++ or ~ or :: or pretty much any Scala operator method name. To make it even more difficult, an implicit conversion may be applied to one of the operands, so the class providing the operator method may not be the same as the declared class of the operand in the source code.

In order to simplify the task of finding Scala operators, I have collected the operator names from the standard Scala classes in this one place. When you are looking for an operator, you can just come to this page and search for the operator within this page using your browser's Find function. You will still need to figure out which of the classes that defines that operator is the right one for your situation, and whether an implicit conversion is being applied.

Of course this page can't list every operator you might find, because Scala allows new operators to be defined in a class. And there is the chance that my list is missing some operators, due either to incomplete or inconsistent documentation of a Scala class, or a bug in my extraction script. But at least it covers most of the standard operators, which should get you further along than having nothing.

Remember that operators that end in : are right associative and the invoking object appears on the right side of the operator. The unary operators + - ! ~ are defined by methods named unary_op where op is one of the four characters; look for those method names at the end of the list.

These operators were extracted from the Scala 2.7.2 final API documentation using the script given below. Many of the methods do not include a summary documentation line, so those appear blank below. Some include a summary that takes more than one line in the source file; my simple little script only picks up the first line. The links point to the on-line API documentation.

Scala Operators

!! AbstractActor
!! Actor Sends msg to this actor and immediately ...
!! Proxy
! Actor Sends msg to this actor (asynchronous).
! Channel Sends a message to this Channel.
! OutputChannel Sends msg to this ...
! Proxy Sends msg to this ...
!= Any o != arg0 is the same as !(o == (arg0)).
!= AnyRef
!= Boolean
!= Byte
!= Char
!= Double
!= Float
!= Int
!= Long
!= Short
!? AbstractActor
!? Actor Sends msg to this actor and awaits reply ...
!? Channel Sends a message to this Channel and ...
!? Proxy
% BigInt Remainder of BigInts
% Byte
% Char
% Double
% Float
% Int
% Long
% Short
% Elem Returns a new element with updated attributes, resolving namespace uris from this element's scope. ...
&&& Parsers.Parser
&& Boolean
&+ NodeBuffer Append given object to this buffer, returns reference on this NodeBuffer ...
& BigInt Bitwise and of BigInts
& Boolean
& Byte
& Char
& Enumeration.Set32 Equivalent to * for bit sets. ...
& Enumeration.Set64 Equivalent to * for bit sets. ...
& Enumeration.SetXX Equivalent to * for bit sets. ...
& Int
& Long
& Short
&~ BigInt Bitwise and-not of BigInts. Returns a BigInt whose value is (this & ~that).
&~ Enumeration.Set32 Equivalent to - for bit sets. ...
&~ Enumeration.Set64 Equivalent to - for bit sets. ...
&~ Enumeration.SetXX Equivalent to - for bit sets. ...
>>> Byte
>>> Char
>>> Int
>>> Long
>>> Short
>> BigInt (Signed) rightshift of BigInt
>> Byte
>> Char
>> Int
>> Long
>> Short
>> Parsers.Parser Returns into(fq)
>> Parsers.Parser Returns into(fq)
> BigDecimal Greater-than comparison of BigDecimals
> BigInt Greater-than comparison of BigInts
> Byte
> Char
> Double
> Float
> Int
> Long
> Ordered
> PartiallyOrdered
> Short
>= BigDecimal Greater-than-or-equals comparison of BigDecimals
>= BigInt Greater-than-or-equals comparison of BigInts
>= Byte
>= Char
>= Double
>= Float
>= Int
>= Long
>= Ordered
>= PartiallyOrdered
>= Short
<< BigInt Leftshift of BigInt
<< Byte
<< Char
<< Int
<< Long
<< Short
<< Buffer Send a message to this scriptable object.
<< BufferProxy Send a message to this scriptable object.
<< Map Send a message to this scriptable object.
<< MapProxy Send a message to this scriptable object.
<< Scriptable Send a message to this scriptable object.
<< Set Send a message to this scriptable object.
<< SetProxy Send a message to this scriptable object.
<< SynchronizedBuffer Send a message to this scriptable object.
<< SynchronizedMap Send a message to this scriptable object.
<< SynchronizedSet Send a message to this scriptable object.
< BigDecimal Less-than of BigDecimals
< BigInt Less-than of BigInts
< Byte
< Char
< Double
< Float
< Int
< Long
< Ordered
< PartiallyOrdered
< Short
< OffsetPosition Compare this position to another, by first comparing their line numbers, ...
< Position Compare this position to another, by first comparing their line numbers, ...
<= BigDecimal Less-than-or-equals comparison of BigDecimals
<= BigInt Less-than-or-equals comparison of BigInts
<= Byte
<= Char
<= Double
<= Float
<= Int
<= Long
<= Ordered
<= PartiallyOrdered
<= Short
<~ Parsers.Parser A parser combinator for sequential composition which keeps only the left result
** Enumeration.SetXX
** Set Intersect. It computes an intersection with set that. ...
** Set This method is an alias for intersect. ...
* BigDecimal Multiplication of BigDecimals
* BigInt Multiplication of BigInts
* Byte
* Char
* Double
* Float
* Int
* Long
* Short
* Set
* RichString return n times the current string
* Parsers.Parser Returns a parser that repeatedly parses what this parser parses, interleaved with the `sep' parser. ...
* Parsers.Parser Returns a parser that repeatedly parses what this parser parses
* Parsers.Parser Returns a parser that repeatedly parses what this parser parses, interleaved with the `sep' parser. ...
* Parsers.Parser Returns a parser that repeatedly parses what this parser parses, interleaved with the `sep' parser.
* Parsers.Parser Returns a parser that repeatedly parses what this parser parses
++: ArrayBuffer Prepends a number of elements provided by an iterable object ...
++: Buffer Prepends a number of elements provided by an iterable object ...
++: BufferProxy Prepends a number of elements provided by an iterable object ...
++: SynchronizedBuffer Prepends a number of elements provided by an iterable object ...
++ Array Returns an array consisting of all elements of this array followed ...
++ Enumeration.SetXX
++ Iterable Appends two iterable objects.
++ IterableProxy Appends two iterable objects.
++ Iterator Returns a new iterator that first yields the elements of this ...
++ List Appends two list objects.
++ RandomAccessSeq Appends two iterable objects.
++ RandomAccessSeqProxy Appends two iterable objects.
++ Seq Appends two iterable objects.
++ SeqProxy Appends two iterable objects.
++ IntMap Add a sequence of key/value pairs to this map.
++ LongMap Add a sequence of key/value pairs to this map.
++ Map Add a sequence of key/value pairs to this map.
++ Set Add all the elements provided by an iterator ...
++ Set Add all the elements provided by an iterator to the set.
++ SortedMap Add a sequence of key/value pairs to this map.
++ SortedSet Add all the elements provided by an iterator ...
++ Stack Push all elements provided by the given iterable object onto ...
++ Stack Push all elements provided by the given iterator object onto ...
++ TreeHashMap
++ TreeHashMap Add a sequence of key/value pairs to this map.
++ Collection Operator shortcut for addAll.
++ Set Operator shortcut for addAll.
++ ArrayBuffer Appends two iterable objects.
++ Buffer Appends a number of elements provided by an iterable object ...
++ Buffer Appends a number of elements provided by an iterator ...
++ Buffer Appends two iterable objects.
++ BufferProxy Appends a number of elements provided by an iterable object ...
++ Map Add a sequence of key/value pairs to this map.
++ MapProxy Add a sequence of key/value pairs to this map.
++ PriorityQueue
++ Set Add all the elements provided by an iterator ...
++ SynchronizedBuffer Appends a number of elements provided by an iterable object ...
++ RichString Appends two iterable objects.
++ RichStringBuilder Appends a number of elements provided by an iterable object ...
++ RichStringBuilder Appends two iterable objects.
++= Map Add a sequence of key/value pairs to this map.
++= MapWrapper Add a sequence of key/value pairs to this map.
++= ArrayBuffer Appends a number of elements in an array
++= ArrayBuffer Appends a number of elements provided by an iterable object ...
++= ArrayStack Pushes all the provided elements onto the stack.
++= Buffer Appends a number of elements in an array
++= Buffer Appends a number of elements provided by an iterable object ...
++= Buffer Appends a number of elements provided by an iterator
++= BufferProxy Appends a number of elements provided by an iterable object ...
++= Map Add a sequence of key/value pairs to this map.
++= MapProxy Add a sequence of key/value pairs to this map.
++= PriorityQueue Adds all elements provided by an Iterable object ...
++= PriorityQueue Adds all elements provided by an iterator into the priority queue.
++= PriorityQueueProxy Adds all elements provided by an Iterable object ...
++= PriorityQueueProxy Adds all elements provided by an iterator into the priority queue.
++= Queue Adds all elements provided by an Iterable object ...
++= Queue Adds all elements provided by an iterator ...
++= QueueProxy Adds all elements provided by an Iterable object ...
++= QueueProxy Adds all elements provided by an iterator ...
++= Set Add all the elements provided by an iterator ...
++= SetProxy Add all the elements provided by an iterator ...
++= Stack Pushes all elements provided by an Iterable object ...
++= Stack Pushes all elements provided by an iterator ...
++= StackProxy Pushes all elements provided by an Iterable object ...
++= StackProxy Pushes all elements provided by an iterator ...
++= SynchronizedBuffer Appends a number of elements provided by an iterable object ...
++= SynchronizedMap Add a sequence of key/value pairs to this map.
++= SynchronizedPriorityQueue Adds all elements provided by an Iterable object ...
++= SynchronizedPriorityQueue Adds all elements provided by an iterator into the priority queue.
++= SynchronizedQueue Adds all elements provided by an Iterable object ...
++= SynchronizedQueue Adds all elements provided by an iterator ...
++= SynchronizedSet Add all the elements provided by an iterator ...
++= SynchronizedStack Pushes all elements provided by an Iterable object ...
++= SynchronizedStack Pushes all elements provided by an iterator ...
++= RichStringBuilder Appends a number of elements provided by an iterable object ...
+: ArrayBuffer Prepends a single element to this buffer and return ...
+: Buffer Prepend a single element to this buffer and return ...
+: BufferProxy Prepend a single element to this buffer and return ...
+: ListBuffer Prepends a single element to this buffer. It takes constant ...
+: ObservableBuffer Prepend a single element to this buffer and return ...
+: SynchronizedBuffer Prepend a single element to this buffer and return ...
+: RichStringBuilder Prepend a single element to this buffer and return ...
+: BufferWrapper Prepend a single element to this buffer and return ...
+: RefBuffer Prepend a single element to this buffer and return ...
+ BigDecimal Addition of BigDecimals
+ BigInt Addition of BigInts
+ Byte
+ Char
+ Double
+ Enumeration.SetXX Create a new set with an additional element.
+ Float
+ Int
+ List
+ Long
+ Short
+ EmptySet Create a new set with an additional element.
+ HashSet Create a new set with an additional element.
+ ListSet.Node This method creates a new set with an additional element.
+ ListSet This method creates a new set with an additional element.
+ Map
+ Map Add a key/value pair to this map.
+ Map Add two or more key/value pairs to this map.
+ Queue Creates a new queue with element added at the end ...
+ Queue Returns a new queue with all all elements provided by ...
+ Set Add two or more elements to this set.
+ Set Create a new set with an additional element.
+ Set1 Create a new set with an additional element.
+ Set2 Create a new set with an additional element.
+ Set3 Create a new set with an additional element.
+ Set4 Create a new set with an additional element.
+ SortedMap Add a key/value pair to this map.
+ SortedMap Add two or more key/value pairs to this map.
+ SortedSet Create a new set with an additional element.
+ Stack Push all elements provided by the given iterable object onto ...
+ Stack Push an element on the stack.
+ TreeSet A new TreeSet with the entry added is returned,
+ Buffer adds "a" from the collection. Useful for chaining.
+ Collection adds "a" from the collection. Useful for chaining.
+ Map Add a key/value pair to this map.
+ Set adds "a" from the collection. Useful for chaining.
+ Buffer Append a single element to this buffer and return ...
+ BufferProxy Append a single element to this buffer and return ...
+ Map Add a key/value pair to this map.
+ Map Add two or more key/value pairs to this map.
+ MapProxy Add a key/value pair to this map.
+ MapProxy Add two or more key/value pairs to this map.
+ ObservableBuffer Append a single element to this buffer and return ...
+ PriorityQueue
+ Set Add a new element to the set.
+ Set Add two or more elements to this set.
+ SynchronizedBuffer Append a single element to this buffer and return ...
+ Parsers.Parser Returns a parser that repeatedly (at least once) parses what this parser parses.
+ Parsers.Parser Returns a parser that repeatedly (at least once) parses what this parser parses.
+= Collection adds "a" from the collection.
+= Map Add a key/value pair to this map.
+= ArrayBuffer Appends a single element to this buffer and returns ...
+= ArrayStack Alias for push.
+= BitSet Sets i-th bit to true. ...
+= Buffer Append a single element to this buffer.
+= BufferProxy Append a single element to this buffer.
+= HashSet Add a new element to the set.
+= ImmutableSetAdaptor Add a new element to the set.
+= JavaSetAdaptor Add a new element to the set.
+= LinkedHashSet Add a new element to the set.
+= ListBuffer Appends a single element to this buffer. It takes constant ...
+= Map Add a key/value pair to this map.
+= Map Add two or more key/value pairs to this map.
+= Map This method defines syntactic sugar for adding or modifying ...
+= MapProxy Add a key/value pair to this map.
+= MapProxy Add two or more key/value pairs to this map.
+= ObservableSet Add a new element to the set.
+= PriorityQueue Add two or more elements to this set.
+= PriorityQueue Inserts a single element into the priority queue.
+= PriorityQueueProxy Inserts a single element into the priority queue.
+= Queue Inserts a single element at the end of the queue.
+= QueueProxy Inserts a single element at the end of the queue.
+= Set Add a new element to the set.
+= Set Add two or more elements to this set.
+= SetProxy Add a new element to the set.
+= Stack Pushes a single element on top of the stack.
+= StackProxy Pushes a single element on top of the stack.
+= SynchronizedBuffer Append a single element to this buffer.
+= SynchronizedMap Add a key/value pair to this map.
+= SynchronizedMap Add two or more key/value pairs to this map.
+= SynchronizedPriorityQueue Inserts a single element into the priority queue.
+= SynchronizedQueue Inserts a single element at the end of the queue.
+= SynchronizedSet Add a new element to the set.
+= SynchronizedStack Pushes a single element on top of the stack.
+= RichStringBuilder Append a single element to this buffer.
+= Reactions Add a reaction.
+= RefBuffer Append a single element to this buffer.
+= CachedFileStorage adds a node, setting this.dirty to true as a side effect
+= IndexedStorage adds a node, setting this.dirty to true as a side effect
+= SetStorage adds a node, setting this.dirty to true as a side effect
-> Map.MapTo
-> Map.MapTo
-- List Computes the difference between this list and the given list ...
-- Map Remove a sequence of keys from this map
-- Set Remove all the elements provided by an iterator ...
-- SortedMap Remove a sequence of keys from this map
-- MutableIterable Operator shortcut for removeAll.
-- Set Operator shortcut for removeAll.
-- Map Remove a sequence of keys from this map
-- MapProxy Remove a sequence of keys from this map
-- Set Remove all the elements provided by an iterator ...
--= Map Remove a sequence of keys from this map
--= MapProxy Remove a sequence of keys from this map
--= Set Remove all the elements provided by an iterator ...
--= SetProxy Remove all the elements provided by an iterator ...
--= SynchronizedMap Remove a sequence of keys from this map
--= SynchronizedSet Remove all the elements provided by an iterator ...
- BigDecimal Subtraction of BigDecimals
- BigInt Subtraction of BigInts
- Byte
- Char
- Double
- Enumeration.SetXX Remove a single element from a set.
- Float
- Int
- List Computes the difference between this list and the given object ...
- Long
- Short
- EmptyMap Remove a key from this map
- EmptySet Remove a single element from a set.
- HashMap Remove a key from this map
- HashSet Remove a single element from a set.
- IntMap Remove a key from this map
- ListMap.Node Creates a new mapping without the given key. ...
- ListMap This creates a new mapping without the given key. ...
- ListSet.Node - can be used to remove a single element from ...
- ListSet - can be used to remove a single element from ...
- LongMap Remove a key from this map
- Map Remove a key from this map
- Map Remove two or more keys from this map
- Map1 Remove a key from this map
- Map2 Remove a key from this map
- Map3 Remove a key from this map
- Map4 Remove a key from this map
- Set Remove a single element from a set.
- Set Remove two or more elements from this set.
- Set1 Remove a single element from a set.
- Set2 Remove a single element from a set.
- Set3 Remove a single element from a set.
- Set4 Remove a single element from a set.
- SortedMap Remove a key from this map
- SortedMap Remove two or more keys from this map
- TreeHashMap Remove a key from this map
- TreeMap Remove a key from this map
- TreeSet Remove a single element from a set.
- UnbalancedTreeMap.Node Remove a key from this map
- UnbalancedTreeMap Remove a key from this map
- Map Remove a key from this map
- MutableIterable
- Set
- ListBuffer Removes a single element from the buffer and return ...
- Map Remove a key from this map
- Map Remove two or more keys from this map
- MapProxy Remove a key from this map
- MapProxy Remove two or more keys from this map
- Set Remove a new element from the set.
- Set Remove two or more elements from this set.
-= Buffer removes "a" from the collection.
-= Collection removes "a" from the collection.
-= Map Remove a key from this map, noop if key is not present.
-= BitSet Clears the i-th bit.
-= Buffer Removes a single element from this buffer, at its first occurrence. ...
-= HashMap Remove a key from this map, noop if key is not present.
-= HashSet Removes a single element from a set.
-= ImmutableMapAdaptor Remove a key from this map, noop if key is not present.
-= ImmutableSetAdaptor Removes a single element from a set.
-= JavaMapAdaptor Remove a key from this map, noop if key is not present.
-= JavaSetAdaptor Removes a single element from a set.
-= LinkedHashMap Remove a key from this map, noop if key is not present.
-= LinkedHashSet Removes a single element from a set.
-= ListBuffer Remove a single element from this buffer. It takes linear time ...
-= Map Remove a key from this map, noop if key is not present.
-= Map Remove two or more keys from this map
-= MapProxy Remove a key from this map, noop if key is not present.
-= MapProxy Remove two or more keys from this map
-= ObservableMap Remove a key from this map, noop if key is not present.
-= ObservableSet Removes a single element from a set.
-= OpenHashMap Remove a key from this map, noop if key is not present.
-= Set Remove two or more elements from this set.
-= Set Removes a single element from a set.
-= SetProxy Removes a single element from a set.
-= SynchronizedMap Remove a key from this map, noop if key is not present.
-= SynchronizedMap Remove two or more keys from this map
-= SynchronizedSet Removes a single element from a set.
-= Reactions Remove the given reaction.
-= CachedFileStorage removes a tree, setting this.dirty to true as a side effect
-= IndexedStorage removes a tree, setting this.dirty to true as a side effect
/% BigInt Returns a pair of two BigInts containing (this / that) and (this % that).
/: Iterable Similar to foldLeft but can be used as ...
/: IterableProxy Similar to foldLeft but can be used as ...
/: Iterator Similar to foldLeft but can be used as ...
/ BigDecimal Division of BigDecimals
/ BigInt Division of BigInts
/ Byte
/ Char
/ Double
/ Float
/ Int
/ Long
/ Short
:/: Document
::: List
:: List
:: Document
:\ Iterable An alias for foldRight. ...
:\ IterableProxy An alias for foldRight. ...
:\ Iterator An alias for foldRight. ...
== Any o == arg0 is the same as o.equals(arg0).
== AnyRef o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).
== Boolean
== Byte
== Char
== Double
== Float
== Int
== Long
== Short
? Actor Receives the next message from this actor's mailbox.
? Channel Receives the next message from this Channel.
? InputChannel Receives the next message from this Channel.
? Parsers.Parser Returns a parser that optionally parses what this parser parses.
? Parsers.Parser Returns a parser that optionally parses what this parser parses.
\ NodeSeq Projection function. Similar to XPath, use this \ "foo"
\\ NodeSeq projection function. Similar to XPath, use this \\ 'foo
^ BigInt Bitwise exclusive-or of BigInts
^ Boolean
^ Byte
^ Char
^ Int
^ Long
^ Short
^? Parsers.Parser A parser combinator for partial function application
^? Parsers.Parser A parser combinator for partial function application
^^ Parsers.Parser A parser combinator for function application
^^ Parsers.Parser A parser combinator for function application
^^ Parsers.UnitParser A parser combinator for function application
^^^ Parsers.Parser
| BigInt Bitwise or of BigInts
| Boolean
| Byte
| Char
| Enumeration.Set32 Equivalent to ++ for bit sets. Returns a set ...
| Enumeration.Set32 Equivalent to + for bit sets. Returns a set ...
| Enumeration.Set64 Equivalent to ++ for bit sets. Returns a set ...
| Enumeration.Set64 Equivalent to + for bit sets. Returns a set ...
| Enumeration.SetXX Equivalent to ++ for bit sets. Returns a set ...
| Enumeration.SetXX Equivalent to + for bit sets. Returns a set ...
| Int
| Long
| Short
| Parsers.Parser A parser combinator for alternative composition
| Parsers.Parser A parser combinator for alternative composition
| Parsers.UnitParser A parser combinator for alternative composition
|| Boolean
||| Parsers.Parser
||| Parsers.Parser A parser combinator for alternative with longest match composition
||| Parsers.Parser A parser combinator for alternative with longest match composition
||| Parsers.UnitParser A parser combinator for alternative with longest match composition
~! Parsers.Parser A parser combinator for non-back-tracking sequential composition
~! Parsers.Parser A parser combinator for non-back-tracking sequential composition with a unit-parser
~! Parsers.Parser A parser combinator for non-back-tracking sequential composition
~! Parsers.UnitParser A parser combinator for non-back-tracking sequential composition with a unit-parser
~! Parsers.UnitParser A parser combinator for non-back-tracking sequential composition
~> Parsers.Parser A parser combinator for sequential composition which keeps only the right result
~ BigInt Returns the bitwise complement of this BigNum
~ Parsers.OnceParser A parser combinator for sequential composition
~ Parsers.Parser A parser combinator for sequential composition
~ Parsers
~ Parsers.OnceParser A parser combinator for sequential composition with a unit-parser
~ Parsers.OnceParser A parser combinator for sequential composition
~ Parsers.Parser A parser combinator for sequential composition with a unit-parser
~ Parsers.Parser A parser combinator for sequential composition
~ Parsers.UnitOnceParser A parser combinator for sequential composition with a unit-parser
~ Parsers.UnitOnceParser A parser combinator for sequential composition
~ Parsers.UnitParser A parser combinator for sequential composition with a unit-parser
~ Parsers.UnitParser A parser combinator for sequential composition
unary_! Boolean
unary_+ Byte
unary_+ Char
unary_+ Double
unary_+ Float
unary_+ Int
unary_+ Long
unary_+ Short
unary_- BigDecimal Returns a BigDecimal whose value is the negation of this BigDecimal
unary_- BigInt Returns a BigInt whose value is the negation of this BigInt
unary_- Byte
unary_- Char
unary_- Double
unary_- Float
unary_- Int
unary_- Long
unary_- Short
unary_~ Byte
unary_~ Char
unary_~ Int
unary_~ Long
unary_~ Short

Extraction Script

I ran this script under Mac OS X 10.4.11, directed the output to a file, and included that file in this post.
#!/bin/sh - #Extract scala operator names from scaladoc files. #cd to the "api" directory containing the scala API docs, then #run this script and redirect stdout to a file. docsubdir=scala TROOT="http://www.scala-lang.org/docu/files/api" find $docsubdir -name \*.html | \ xargs grep -A 4 'class="signature"' | \ grep -E " <em><a href.*_self|<div>" | \ grep -A 1 -E '<em>.*"_self">([^a-zA-Z0-9_]|unary_)' | \ grep -v '^--' | \ sed -e 's|<em>.*>\(.*\)</a></em>|\1|' | \ sed -e 's/html-/html/' | \ sed -e 's/.*\(<div>.*\)/\1/' | \ uniq | \ awk ' !/<div>/ { if (d!="") { print d; d="" } } {d=d" "$0} ' | \ sed -e 's/^[ ]*//' | \ sed -e 's|\(<div>.*[^>]\)$|\1 ...</div>|' | \ sed -e 's/<div>/<span>/' -e 's|</div>|</span>|' | \ sort +1 | uniq | \ sed -e 's|^\([^ ]*/\)\(.*\).html[ ]*\([^ ]*\)\(.*\)$|<br/><b>\3</b> <a href="'$TROOT'/\1\2.html">\2</a>\4|' | \ grep -v '^<br/><b>[a-tv-zA-Z]' | \ grep -v '[a-zA-Z]\$[a-zA-Z]' | \ sed -e 's/unary_/~~~~unary_/' | sort | sed -e 's/~~~~unary_/unary_/' | \ cat -
Updated 2008-12-21: Added summary line before Contents list.

4 comments:

Doug Holton said...

I'm seeing other scala code that uses operators I don't understand, and they aren't listed here.

For example see this sample:
http://code.google.com/p/slinky2/source/browse/trunk/demo/src/main/slinky/demo/App.scala

Line 43: "say(phrase | "Pass the phrase request parameter")"

Does that mean if phrase is null, use the string instead? I didn't know the | operator could be used like that.

Line 105: ") >"

Does the > operator there mean "map"? I didn't know the List class had an operator like that. It's not in the docs.

I'd almost prefer people used words for non-common operators instead of symbols.

Jim McBeath said...

Doug: Indeed, Scala can be hard to read. The combination of type inference and implicit conversions can make it difficult to determine the type of a variable, and that's what you need to know to find out what the operator does.

A well designed library tries to use operator symbols in ways that are generally accepted as "standard": + means add or concatenate two things, += means add something to the object, | means alternate, >>= means bind, etc. But sometimes the interpretation is not so straightforward. ! can mean send, but that doesn't necessarily tell you what it does. The class author is free to use whatever operator symbols he wants, and his interpretation of "alternate" or "add" may not match what you expect. The bottom line is that an operator might be doing something very different from what you expect if it comes from a different class than you thought it did.

I am not familiar with the example you cite, but in Tony's announcement of slinky on the Scala mailing list, he says it uses combinators for putting together Request=>Response functions, so I would guess those operators are combinators, perhaps in
slinky.http.request.Request
or slinky.http.response.Response.

If you download the slinky source, maybe you can run scaladoc on it and then run the above extraction script on the scaladoc to get a list of the operators in that package.

As far as using words instead of operators, some people think operators are sometimes superior. In a recent post on the Scala mailing list, Ricky Clarkson said "Generally, words interfere with your reading far more than symbols do," with Scala's parser combinators as an example.

Unknown said...

Great script. And thanks for the data munging script as well

MEMark said...

The link to Rickys post has changed. This is the new one:
http://scala-programming-language.1934581.n4.nabble.com/Too-many-uses-for-quot-gt-quot-in-Scala-td2000270.html#a2000271