- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
the ultimate scala cheat sheet
hi community,
i felt the desire to put together a scala cheat sheet. the reason is
that even after two years, i still find new features/tricks which don't
seem to be clearly documented - they exist, but are scattered across the
internet. there is already a cheat sheet, but it only covers a fraction
of what i am imagining here. there are some examples on scala-lang, but
i had to read them several times since they are not very clear. there
are some good blogs, but again, you have to look for them. i believe
that having a single, well structured pdf will make people more
comfortable with scala if they are new, should make it easier to
convince heretics to believe in scala :) and take away the fear of the
unknown complexity.
it's probably going to be bigger than the usual cheat sheet so it's more
like a wallpaper, but splitting it up into subsections should help.
also, i want to focus on productivity boost features and keep it on a
level that a random java dev should be able to understand (i am thinking
about avoiding scary method signatures here and use java code as
examples of how this would look like in java or maybe other languages as
well)
send your findings/knowledge to me/this list :)
i'll collect them and put them together.










Re: the ultimate scala cheat sheet
i did some research and wrote an example showing how implicits are
resolved. take a look at it and if there is a mistake, please notify me :)
https://gist.github.com/1649497
Am 21.12.2011 21:02, schrieb HamsterofDeath:
> hi community,
>
> i felt the desire to put together a scala cheat sheet. the reason is
> that even after two years, i still find new features/tricks which don't
> seem to be clearly documented - they exist, but are scattered across the
> internet. there is already a cheat sheet, but it only covers a fraction
> of what i am imagining here. there are some examples on scala-lang, but
> i had to read them several times since they are not very clear. there
> are some good blogs, but again, you have to look for them. i believe
> that having a single, well structured pdf will make people more
> comfortable with scala if they are new, should make it easier to
> convince heretics to believe in scala :) and take away the fear of the
> unknown complexity.
>
> it's probably going to be bigger than the usual cheat sheet so it's more
> like a wallpaper, but splitting it up into subsections should help.
> also, i want to focus on productivity boost features and keep it on a
> level that a random java dev should be able to understand (i am thinking
> about avoiding scary method signatures here and use java code as
> examples of how this would look like in java or maybe other languages as
> well)
>
> send your findings/knowledge to me/this list :)
> i'll collect them and put them together.
>
Re: the ultimate scala cheat sheet
since no one objected, here's the whole thing as a pdf:
https://rapidshare.com/files/3045603786/scc.pdf
Am 20.01.2012 21:54, schrieb HamsterofDeath:
> i did some research and wrote an example showing how implicits are
> resolved. take a look at it and if there is a mistake, please notify me :)
>
> https://gist.github.com/1649497
>
> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>> hi community,
>>
>> i felt the desire to put together a scala cheat sheet. the reason is
>> that even after two years, i still find new features/tricks which don't
>> seem to be clearly documented - they exist, but are scattered across the
>> internet. there is already a cheat sheet, but it only covers a fraction
>> of what i am imagining here. there are some examples on scala-lang, but
>> i had to read them several times since they are not very clear. there
>> are some good blogs, but again, you have to look for them. i believe
>> that having a single, well structured pdf will make people more
>> comfortable with scala if they are new, should make it easier to
>> convince heretics to believe in scala :) and take away the fear of the
>> unknown complexity.
>>
>> it's probably going to be bigger than the usual cheat sheet so it's more
>> like a wallpaper, but splitting it up into subsections should help.
>> also, i want to focus on productivity boost features and keep it on a
>> level that a random java dev should be able to understand (i am thinking
>> about avoiding scary method signatures here and use java code as
>> examples of how this would look like in java or maybe other languages as
>> well)
>>
>> send your findings/knowledge to me/this list :)
>> i'll collect them and put them together.
>>
>
Re: the ultimate scala cheat sheet
It told me the file was not available.
On Wed, Jan 25, 2012 at 17:34, HamsterofDeath wrote:
> since no one objected, here's the whole thing as a pdf:
> https://rapidshare.com/files/3045603786/scc.pdf
>
>
> Am 20.01.2012 21:54, schrieb HamsterofDeath:
>> i did some research and wrote an example showing how implicits are
>> resolved. take a look at it and if there is a mistake, please notify me :)
>>
>> https://gist.github.com/1649497
>>
>> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>>> hi community,
>>>
>>> i felt the desire to put together a scala cheat sheet. the reason is
>>> that even after two years, i still find new features/tricks which don't
>>> seem to be clearly documented - they exist, but are scattered across the
>>> internet. there is already a cheat sheet, but it only covers a fraction
>>> of what i am imagining here. there are some examples on scala-lang, but
>>> i had to read them several times since they are not very clear. there
>>> are some good blogs, but again, you have to look for them. i believe
>>> that having a single, well structured pdf will make people more
>>> comfortable with scala if they are new, should make it easier to
>>> convince heretics to believe in scala :) and take away the fear of the
>>> unknown complexity.
>>>
>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>> like a wallpaper, but splitting it up into subsections should help.
>>> also, i want to focus on productivity boost features and keep it on a
>>> level that a random java dev should be able to understand (i am thinking
>>> about avoiding scary method signatures here and use java code as
>>> examples of how this would look like in java or maybe other languages as
>>> well)
>>>
>>> send your findings/knowledge to me/this list :)
>>> i'll collect them and put them together.
>>>
>>
>
Re: the ultimate scala cheat sheet
rapidshare lies, i can download it.
Am 25.01.2012 20:45, schrieb Daniel Sobral:
> It told me the file was not available.
>
> On Wed, Jan 25, 2012 at 17:34, HamsterofDeath wrote:
>> since no one objected, here's the whole thing as a pdf:
>> https://rapidshare.com/files/3045603786/scc.pdf
>>
>>
>> Am 20.01.2012 21:54, schrieb HamsterofDeath:
>>> i did some research and wrote an example showing how implicits are
>>> resolved. take a look at it and if there is a mistake, please notify me :)
>>>
>>> https://gist.github.com/1649497
>>>
>>> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>>>> hi community,
>>>>
>>>> i felt the desire to put together a scala cheat sheet. the reason is
>>>> that even after two years, i still find new features/tricks which don't
>>>> seem to be clearly documented - they exist, but are scattered across the
>>>> internet. there is already a cheat sheet, but it only covers a fraction
>>>> of what i am imagining here. there are some examples on scala-lang, but
>>>> i had to read them several times since they are not very clear. there
>>>> are some good blogs, but again, you have to look for them. i believe
>>>> that having a single, well structured pdf will make people more
>>>> comfortable with scala if they are new, should make it easier to
>>>> convince heretics to believe in scala :) and take away the fear of the
>>>> unknown complexity.
>>>>
>>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>>> like a wallpaper, but splitting it up into subsections should help.
>>>> also, i want to focus on productivity boost features and keep it on a
>>>> level that a random java dev should be able to understand (i am thinking
>>>> about avoiding scary method signatures here and use java code as
>>>> examples of how this would look like in java or maybe other languages as
>>>> well)
>>>>
>>>> send your findings/knowledge to me/this list :)
>>>> i'll collect them and put them together.
>>>>
>
>
Re: the ultimate scala cheat sheet
I don't like calling the value classes "primitives", because it
implies the distinction Java has and Scala doesn't.
On Wed, Jan 25, 2012 at 18:30, HamsterofDeath wrote:
> rapidshare lies, i can download it.
>
> Am 25.01.2012 20:45, schrieb Daniel Sobral:
>> It told me the file was not available.
>>
>> On Wed, Jan 25, 2012 at 17:34, HamsterofDeath wrote:
>>> since no one objected, here's the whole thing as a pdf:
>>> https://rapidshare.com/files/3045603786/scc.pdf
>>>
>>>
>>> Am 20.01.2012 21:54, schrieb HamsterofDeath:
>>>> i did some research and wrote an example showing how implicits are
>>>> resolved. take a look at it and if there is a mistake, please notify me :)
>>>>
>>>> https://gist.github.com/1649497
>>>>
>>>> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>>>>> hi community,
>>>>>
>>>>> i felt the desire to put together a scala cheat sheet. the reason is
>>>>> that even after two years, i still find new features/tricks which don't
>>>>> seem to be clearly documented - they exist, but are scattered across the
>>>>> internet. there is already a cheat sheet, but it only covers a fraction
>>>>> of what i am imagining here. there are some examples on scala-lang, but
>>>>> i had to read them several times since they are not very clear. there
>>>>> are some good blogs, but again, you have to look for them. i believe
>>>>> that having a single, well structured pdf will make people more
>>>>> comfortable with scala if they are new, should make it easier to
>>>>> convince heretics to believe in scala :) and take away the fear of the
>>>>> unknown complexity.
>>>>>
>>>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>>>> like a wallpaper, but splitting it up into subsections should help.
>>>>> also, i want to focus on productivity boost features and keep it on a
>>>>> level that a random java dev should be able to understand (i am thinking
>>>>> about avoiding scary method signatures here and use java code as
>>>>> examples of how this would look like in java or maybe other languages as
>>>>> well)
>>>>>
>>>>> send your findings/knowledge to me/this list :)
>>>>> i'll collect them and put them together.
>>>>>
>>
>>
>
Re: the ultimate scala cheat sheet
the sheet says
"Automatically boxed and unboxed, no special handling like in java (->
int/Integer)"
right next to it. you can write scala code as if there was no jvm level
distinction between int and integer, but at runtime, there still is. i
think that nails it.
Am 25.01.2012 22:02, schrieb Daniel Sobral:
> I don't like calling the value classes "primitives", because it
> implies the distinction Java has and Scala doesn't.
>
> On Wed, Jan 25, 2012 at 18:30, HamsterofDeath wrote:
>> rapidshare lies, i can download it.
>>
>> Am 25.01.2012 20:45, schrieb Daniel Sobral:
>>> It told me the file was not available.
>>>
>>> On Wed, Jan 25, 2012 at 17:34, HamsterofDeath wrote:
>>>> since no one objected, here's the whole thing as a pdf:
>>>> https://rapidshare.com/files/3045603786/scc.pdf
>>>>
>>>>
>>>> Am 20.01.2012 21:54, schrieb HamsterofDeath:
>>>>> i did some research and wrote an example showing how implicits are
>>>>> resolved. take a look at it and if there is a mistake, please notify me :)
>>>>>
>>>>> https://gist.github.com/1649497
>>>>>
>>>>> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>>>>>> hi community,
>>>>>>
>>>>>> i felt the desire to put together a scala cheat sheet. the reason is
>>>>>> that even after two years, i still find new features/tricks which don't
>>>>>> seem to be clearly documented - they exist, but are scattered across the
>>>>>> internet. there is already a cheat sheet, but it only covers a fraction
>>>>>> of what i am imagining here. there are some examples on scala-lang, but
>>>>>> i had to read them several times since they are not very clear. there
>>>>>> are some good blogs, but again, you have to look for them. i believe
>>>>>> that having a single, well structured pdf will make people more
>>>>>> comfortable with scala if they are new, should make it easier to
>>>>>> convince heretics to believe in scala :) and take away the fear of the
>>>>>> unknown complexity.
>>>>>>
>>>>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>>>>> like a wallpaper, but splitting it up into subsections should help.
>>>>>> also, i want to focus on productivity boost features and keep it on a
>>>>>> level that a random java dev should be able to understand (i am thinking
>>>>>> about avoiding scary method signatures here and use java code as
>>>>>> examples of how this would look like in java or maybe other languages as
>>>>>> well)
>>>>>>
>>>>>> send your findings/knowledge to me/this list :)
>>>>>> i'll collect them and put them together.
>>>>>>
>>>
>
>
Re: the ultimate scala cheat sheet
I'm afraid Scala can't yet offer the level of abstraction where you don't have to worry about such things. I'd rather be open about it up front than pretend it doesn't exist.
--Rex
On Wed, Jan 25, 2012 at 4:02 PM, Daniel Sobral <dcsobral [at] gmail [dot] com> wrote:
Re: the ultimate scala cheat sheet
On Wed, Jan 25, 2012 at 04:31:22PM -0500, Rex Kerr wrote:
> If you don't realize that they're primitives on the JVM, you are going to
> get bitten pretty quickly (with performance, with specialization, with Java
> interop, with...). Also, the differences between value and reference types
> are pretty hard to understand outside of that context.
>
> I'm afraid Scala can't yet offer the level of abstraction where you don't
> have to worry about such things. I'd rather be open about it up front than
> pretend it doesn't exist.
I agree with Rex here.
I just finished writing a paper where I had to constantly refer to the
ways in which AnyVal and AnyRef types differ. Beyond things like
boxing, stack allocation and specialization there are basic concerns
like whether null is a legal value.
We can call them "primitives" or something else instead, but it's a
useful and important distinction either way.
Re: the ultimate scala cheat sheet
hi again,
i am stuck. i was told to compile my stuff and take a look at the result
before creating a pull request. i followed the instructions, but i get
this error message:
S:\scala_github\HamsterofDeath-scala.github.com-671225d>jekyll --server
C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
iconv will be deprecated in the future, use String#encode in
stead.
Configuration from
S:/scala_github/HamsterofDeath-scala.github.com-671225d/_config.yml
Building site: S:/scala_github/HamsterofDeath-scala.github.com-671225d
-> S:/scala_github/HamsterofDeath-scala.github.com-671225d/
_site
C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse': (): couldn't
parse YAML at line 3 column 20 (Psych::SyntaxError)
from C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
from C:/Ruby193/lib/ruby/1.9.1/psych.rb:125:in `parse'
from C:/Ruby193/lib/ruby/1.9.1/psych.rb:112:in `load'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:33:in
`read_yaml'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/page.rb:24:in
`initialize'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
`new'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
`block in read_directories'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
`each'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
`read_directories'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:135:in
`block in read_directories'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
`each'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
`read_directories'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in
`read'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in
`process'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in
`'
from C:/Ruby193/bin/jekyll:19:in `load'
from C:/Ruby193/bin/jekyll:19:in `'
my experience considering ruby, YAML, jekyll or whatever i'm doing there
is zero. i just blindly followed some readme. how can i fix this?
Am 21.12.2011 21:02, schrieb HamsterofDeath:
> hi community,
>
> i felt the desire to put together a scala cheat sheet. the reason is
> that even after two years, i still find new features/tricks which don't
> seem to be clearly documented - they exist, but are scattered across the
> internet. there is already a cheat sheet, but it only covers a fraction
> of what i am imagining here. there are some examples on scala-lang, but
> i had to read them several times since they are not very clear. there
> are some good blogs, but again, you have to look for them. i believe
> that having a single, well structured pdf will make people more
> comfortable with scala if they are new, should make it easier to
> convince heretics to believe in scala :) and take away the fear of the
> unknown complexity.
>
> it's probably going to be bigger than the usual cheat sheet so it's more
> like a wallpaper, but splitting it up into subsections should help.
> also, i want to focus on productivity boost features and keep it on a
> level that a random java dev should be able to understand (i am thinking
> about avoiding scary method signatures here and use java code as
> examples of how this would look like in java or maybe other languages as
> well)
>
> send your findings/knowledge to me/this list :)
> i'll collect them and put them together.
>
Re: the ultimate scala cheat sheet
Hi,
> i am stuck. i was told to compile my stuff and take a look at the result
> before creating a pull request.
Very very very sound advice :)
> i followed the instructions, but i get
> this error message:
I don't see anything useful in the below- usually Jekyll returns a more verbose error above the stack trace. I just forked your repo and tried to build it and at least in my case (from the most recently committed version in your repo, 5 days ago) it looks like you've confused jekyll into thinking you've got a head with two columns somewhere, though no idea where.
Regardless, the best thing to do is to perhaps start clean, add sections from your version of the cheatsheet one-by-one, and incrementally build. I would also suggest submitting a clean pull-request eventually as well.
Cheers,
Heather
> S:\scala_github\HamsterofDeath-scala.github.com-671225d>jekyll --server
> C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
> iconv will be deprecated in the future, use String#encode in
> stead.
> Configuration from
> S:/scala_github/HamsterofDeath-scala.github.com-671225d/_config.yml
> Building site: S:/scala_github/HamsterofDeath-scala.github.com-671225d
> -> S:/scala_github/HamsterofDeath-scala.github.com-671225d/
> _site
> C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse': (): couldn't
> parse YAML at line 3 column 20 (Psych::SyntaxError)
> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:125:in `parse'
> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:112:in `load'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:33:in
> `read_yaml'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/page.rb:24:in
> `initialize'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
> `new'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
> `block in read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `each'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:135:in
> `block in read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `each'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in
> `read'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in
> `process'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in
> `'
> from C:/Ruby193/bin/jekyll:19:in `load'
> from C:/Ruby193/bin/jekyll:19:in `'
>
> my experience considering ruby, YAML, jekyll or whatever i'm doing there
> is zero. i just blindly followed some readme. how can i fix this?
>
> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>> hi community,
>>
>> i felt the desire to put together a scala cheat sheet. the reason is
>> that even after two years, i still find new features/tricks which don't
>> seem to be clearly documented - they exist, but are scattered across the
>> internet. there is already a cheat sheet, but it only covers a fraction
>> of what i am imagining here. there are some examples on scala-lang, but
>> i had to read them several times since they are not very clear. there
>> are some good blogs, but again, you have to look for them. i believe
>> that having a single, well structured pdf will make people more
>> comfortable with scala if they are new, should make it easier to
>> convince heretics to believe in scala :) and take away the fear of the
>> unknown complexity.
>>
>> it's probably going to be bigger than the usual cheat sheet so it's more
>> like a wallpaper, but splitting it up into subsections should help.
>> also, i want to focus on productivity boost features and keep it on a
>> level that a random java dev should be able to understand (i am thinking
>> about avoiding scary method signatures here and use java code as
>> examples of how this would look like in java or maybe other languages as
>> well)
>>
>> send your findings/knowledge to me/this list :)
>> i'll collect them and put them together.
>>
>
Re: the ultimate scala cheat sheet
Am 07.01.2012 23:03, schrieb Miller Heather:
> Hi,
>
>> i am stuck. i was told to compile my stuff and take a look at the result
>> before creating a pull request.
> Very very very sound advice :)
>
>> i followed the instructions, but i get
>> this error message:
> I don't see anything useful in the below- usually Jekyll returns a more verbose error above the stack trace. I just forked your repo and tried to build it and at least in my case (from the most recently committed version in your repo, 5 days ago) it looks like you've confused jekyll into thinking you've got a head with two columns somewhere, though no idea where.
why don't i see any errors when previewing my page online?
>
> Regardless, the best thing to do is to perhaps start clean, add sections from your version of the cheatsheet one-by-one, and incrementally build. I would also suggest submitting a clean pull-request eventually as well.
what's the difference between a clean pull request and a "normal" one?
>
> Cheers,
> Heather
>
>
>> S:\scala_github\HamsterofDeath-scala.github.com-671225d>jekyll --server
>> C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
>> iconv will be deprecated in the future, use String#encode in
>> stead.
>> Configuration from
>> S:/scala_github/HamsterofDeath-scala.github.com-671225d/_config.yml
>> Building site: S:/scala_github/HamsterofDeath-scala.github.com-671225d
>> -> S:/scala_github/HamsterofDeath-scala.github.com-671225d/
>> _site
>> C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse': (): couldn't
>> parse YAML at line 3 column 20 (Psych::SyntaxError)
>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:125:in `parse'
>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:112:in `load'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:33:in
>> `read_yaml'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/page.rb:24:in
>> `initialize'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
>> `new'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
>> `block in read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `each'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:135:in
>> `block in read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `each'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in
>> `read'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in
>> `process'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in
>> `'
>> from C:/Ruby193/bin/jekyll:19:in `load'
>> from C:/Ruby193/bin/jekyll:19:in `'
>>
>> my experience considering ruby, YAML, jekyll or whatever i'm doing there
>> is zero. i just blindly followed some readme. how can i fix this?
>>
>> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>>> hi community,
>>>
>>> i felt the desire to put together a scala cheat sheet. the reason is
>>> that even after two years, i still find new features/tricks which don't
>>> seem to be clearly documented - they exist, but are scattered across the
>>> internet. there is already a cheat sheet, but it only covers a fraction
>>> of what i am imagining here. there are some examples on scala-lang, but
>>> i had to read them several times since they are not very clear. there
>>> are some good blogs, but again, you have to look for them. i believe
>>> that having a single, well structured pdf will make people more
>>> comfortable with scala if they are new, should make it easier to
>>> convince heretics to believe in scala :) and take away the fear of the
>>> unknown complexity.
>>>
>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>> like a wallpaper, but splitting it up into subsections should help.
>>> also, i want to focus on productivity boost features and keep it on a
>>> level that a random java dev should be able to understand (i am thinking
>>> about avoiding scary method signatures here and use java code as
>>> examples of how this would look like in java or maybe other languages as
>>> well)
>>>
>>> send your findings/knowledge to me/this list :)
>>> i'll collect them and put them together.
>>>
>
Re: the ultimate scala cheat sheet
On Jan 7, 2012, at 11:15 PM, HamsterofDeath wrote:
> Am 07.01.2012 23:03, schrieb Miller Heather:
>> Hi,
>>
>>> i am stuck. i was told to compile my stuff and take a look at the result
>>> before creating a pull request.
>> Very very very sound advice :)
>>
>>> i followed the instructions, but i get
>>> this error message:
>> I don't see anything useful in the below- usually Jekyll returns a more verbose error above the stack trace. I just forked your repo and tried to build it and at least in my case (from the most recently committed version in your repo, 5 days ago) it looks like you've confused jekyll into thinking you've got a head with two columns somewhere, though no idea where.
>
> why don't i see any errors when previewing my page online?
Read the list of errors that are generated above the stack trace- this is what I'm referring to. To repeat- regardless, I think the problem would be most quickly resolved by starting fresh with the original cheat sheet on docs.scala-lang, adding sections one-by-one, and incrementally building. This is the normal approach, whether your generating documentation or writing code, so it makes sense, right?
>>
>> Regardless, the best thing to do is to perhaps start clean, add sections from your version of the cheatsheet one-by-one, and incrementally build. I would also suggest submitting a clean pull-request eventually as well.
> what's the difference between a clean pull request and a "normal" one?
A clean one is from scratch. Have a look at the workflow for submitting scaladoc pull requests- it's the same in the case of docs.scala-lang.org, with the only difference being that the repository URL is different. In particular, it's a good idea to create a topic branch. See: https://wiki.scala-lang.org/display/SW/Workflow#Workflow-Submittinggithu...
There are a few dozen commits in your current pull request, and it can't be automatically be merged as it is. Which, for me and other docs.scala-lang maintainers, is a big hassle to have to deal with on our end.
Cheers,
Heather
>
>>
>> Cheers,
>> Heather
>>
>>
>>> S:\scala_github\HamsterofDeath-scala.github.com-671225d>jekyll --server
>>> C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
>>> iconv will be deprecated in the future, use String#encode in
>>> stead.
>>> Configuration from
>>> S:/scala_github/HamsterofDeath-scala.github.com-671225d/_config.yml
>>> Building site: S:/scala_github/HamsterofDeath-scala.github.com-671225d
>>> -> S:/scala_github/HamsterofDeath-scala.github.com-671225d/
>>> _site
>>> C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse': (): couldn't
>>> parse YAML at line 3 column 20 (Psych::SyntaxError)
>>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
>>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:125:in `parse'
>>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:112:in `load'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:33:in
>>> `read_yaml'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/page.rb:24:in
>>> `initialize'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
>>> `new'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
>>> `block in read_directories'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>>> `each'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>>> `read_directories'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:135:in
>>> `block in read_directories'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>>> `each'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>>> `read_directories'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in
>>> `read'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in
>>> `process'
>>> from
>>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in
>>> `'
>>> from C:/Ruby193/bin/jekyll:19:in `load'
>>> from C:/Ruby193/bin/jekyll:19:in `'
>>>
>>> my experience considering ruby, YAML, jekyll or whatever i'm doing there
>>> is zero. i just blindly followed some readme. how can i fix this?
>>>
>>> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>>>> hi community,
>>>>
>>>> i felt the desire to put together a scala cheat sheet. the reason is
>>>> that even after two years, i still find new features/tricks which don't
>>>> seem to be clearly documented - they exist, but are scattered across the
>>>> internet. there is already a cheat sheet, but it only covers a fraction
>>>> of what i am imagining here. there are some examples on scala-lang, but
>>>> i had to read them several times since they are not very clear. there
>>>> are some good blogs, but again, you have to look for them. i believe
>>>> that having a single, well structured pdf will make people more
>>>> comfortable with scala if they are new, should make it easier to
>>>> convince heretics to believe in scala :) and take away the fear of the
>>>> unknown complexity.
>>>>
>>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>>> like a wallpaper, but splitting it up into subsections should help.
>>>> also, i want to focus on productivity boost features and keep it on a
>>>> level that a random java dev should be able to understand (i am thinking
>>>> about avoiding scary method signatures here and use java code as
>>>> examples of how this would look like in java or maybe other languages as
>>>> well)
>>>>
>>>> send your findings/knowledge to me/this list :)
>>>> i'll collect them and put them together.
>>>>
>>
>
Re: the ultimate scala cheat sheet
I see you're running Jekyll on Windows, I had problems before using jekyll on this os
and they went away with a reinstall of Jekyll, Ruby and dependencies with a slightly different version mix.
You might be able to use Github pages http://pages.github.com/
to render your fork, I've done it before with another project,
this way you don't have to install anything else other than git.
ML
2012/1/7 Miller Heather <heather [dot] miller [at] epfl [dot] ch>
Re: the ultimate scala cheat sheet
so basically, the error is random. my installation is a completely fresh one, so a reinstall would probably change nothing. looks like i'll have to look for an alternate route
Re: the ultimate scala cheat sheet
On Jan 8, 2012, at 9:36 AM, HamsterofDeath wrote:
Re: the ultimate scala cheat sheet
Did you check if it didn't start up anyway? Whenever I run it, I get
tons of error messages, but it still starts up and it still serves the
pages fine.
On Sat, Jan 7, 2012 at 11:19, HamsterofDeath wrote:
> hi again,
>
> i am stuck. i was told to compile my stuff and take a look at the result
> before creating a pull request. i followed the instructions, but i get
> this error message:
>
> S:\scala_github\HamsterofDeath-scala.github.com-671225d>jekyll --server
> C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
> iconv will be deprecated in the future, use String#encode in
> stead.
> Configuration from
> S:/scala_github/HamsterofDeath-scala.github.com-671225d/_config.yml
> Building site: S:/scala_github/HamsterofDeath-scala.github.com-671225d
> -> S:/scala_github/HamsterofDeath-scala.github.com-671225d/
> _site
> C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse': (): couldn't
> parse YAML at line 3 column 20 (Psych::SyntaxError)
> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:125:in `parse'
> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:112:in `load'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:33:in
> `read_yaml'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/page.rb:24:in
> `initialize'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
> `new'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
> `block in read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `each'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:135:in
> `block in read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `each'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
> `read_directories'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in
> `read'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in
> `process'
> from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in
> `'
> from C:/Ruby193/bin/jekyll:19:in `load'
> from C:/Ruby193/bin/jekyll:19:in `'
>
> my experience considering ruby, YAML, jekyll or whatever i'm doing there
> is zero. i just blindly followed some readme. how can i fix this?
>
> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>> hi community,
>>
>> i felt the desire to put together a scala cheat sheet. the reason is
>> that even after two years, i still find new features/tricks which don't
>> seem to be clearly documented - they exist, but are scattered across the
>> internet. there is already a cheat sheet, but it only covers a fraction
>> of what i am imagining here. there are some examples on scala-lang, but
>> i had to read them several times since they are not very clear. there
>> are some good blogs, but again, you have to look for them. i believe
>> that having a single, well structured pdf will make people more
>> comfortable with scala if they are new, should make it easier to
>> convince heretics to believe in scala :) and take away the fear of the
>> unknown complexity.
>>
>> it's probably going to be bigger than the usual cheat sheet so it's more
>> like a wallpaper, but splitting it up into subsections should help.
>> also, i want to focus on productivity boost features and keep it on a
>> level that a random java dev should be able to understand (i am thinking
>> about avoiding scary method signatures here and use java code as
>> examples of how this would look like in java or maybe other languages as
>> well)
>>
>> send your findings/knowledge to me/this list :)
>> i'll collect them and put them together.
>>
>
Re: the ultimate scala cheat sheet
no, didn't start
Am 07.01.2012 22:20, schrieb Daniel Sobral:
> Did you check if it didn't start up anyway? Whenever I run it, I get
> tons of error messages, but it still starts up and it still serves the
> pages fine.
>
> On Sat, Jan 7, 2012 at 11:19, HamsterofDeath wrote:
>> hi again,
>>
>> i am stuck. i was told to compile my stuff and take a look at the result
>> before creating a pull request. i followed the instructions, but i get
>> this error message:
>>
>> S:\scala_github\HamsterofDeath-scala.github.com-671225d>jekyll --server
>> C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
>> iconv will be deprecated in the future, use String#encode in
>> stead.
>> Configuration from
>> S:/scala_github/HamsterofDeath-scala.github.com-671225d/_config.yml
>> Building site: S:/scala_github/HamsterofDeath-scala.github.com-671225d
>> -> S:/scala_github/HamsterofDeath-scala.github.com-671225d/
>> _site
>> C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse': (): couldn't
>> parse YAML at line 3 column 20 (Psych::SyntaxError)
>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:125:in `parse'
>> from C:/Ruby193/lib/ruby/1.9.1/psych.rb:112:in `load'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:33:in
>> `read_yaml'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/page.rb:24:in
>> `initialize'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
>> `new'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:140:in
>> `block in read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `each'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:135:in
>> `block in read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `each'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:130:in
>> `read_directories'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in
>> `read'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in
>> `process'
>> from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in
>> `'
>> from C:/Ruby193/bin/jekyll:19:in `load'
>> from C:/Ruby193/bin/jekyll:19:in `'
>>
>> my experience considering ruby, YAML, jekyll or whatever i'm doing there
>> is zero. i just blindly followed some readme. how can i fix this?
>>
>> Am 21.12.2011 21:02, schrieb HamsterofDeath:
>>> hi community,
>>>
>>> i felt the desire to put together a scala cheat sheet. the reason is
>>> that even after two years, i still find new features/tricks which don't
>>> seem to be clearly documented - they exist, but are scattered across the
>>> internet. there is already a cheat sheet, but it only covers a fraction
>>> of what i am imagining here. there are some examples on scala-lang, but
>>> i had to read them several times since they are not very clear. there
>>> are some good blogs, but again, you have to look for them. i believe
>>> that having a single, well structured pdf will make people more
>>> comfortable with scala if they are new, should make it easier to
>>> convince heretics to believe in scala :) and take away the fear of the
>>> unknown complexity.
>>>
>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>> like a wallpaper, but splitting it up into subsections should help.
>>> also, i want to focus on productivity boost features and keep it on a
>>> level that a random java dev should be able to understand (i am thinking
>>> about avoiding scary method signatures here and use java code as
>>> examples of how this would look like in java or maybe other languages as
>>> well)
>>>
>>> send your findings/knowledge to me/this list :)
>>> i'll collect them and put them together.
>>>
>
>
Re: the ultimate scala cheat sheet
You do know http://docs.scala-lang.org/cheatsheets/, I assume? Please,
do contribute to it if you think there's things missing in it. You can
contribute directly through this link:
https://github.com/scala/scala.github.com/blob/gh-pages/cheatsheets/inde...
On Wed, Dec 21, 2011 at 18:02, HamsterofDeath wrote:
> hi community,
>
> i felt the desire to put together a scala cheat sheet. the reason is
> that even after two years, i still find new features/tricks which don't
> seem to be clearly documented - they exist, but are scattered across the
> internet. there is already a cheat sheet, but it only covers a fraction
> of what i am imagining here. there are some examples on scala-lang, but
> i had to read them several times since they are not very clear. there
> are some good blogs, but again, you have to look for them. i believe
> that having a single, well structured pdf will make people more
> comfortable with scala if they are new, should make it easier to
> convince heretics to believe in scala :) and take away the fear of the
> unknown complexity.
>
> it's probably going to be bigger than the usual cheat sheet so it's more
> like a wallpaper, but splitting it up into subsections should help.
> also, i want to focus on productivity boost features and keep it on a
> level that a random java dev should be able to understand (i am thinking
> about avoiding scary method signatures here and use java code as
> examples of how this would look like in java or maybe other languages as
> well)
>
> send your findings/knowledge to me/this list :)
> i'll collect them and put them together.
Re: the ultimate scala cheat sheet
But for some reason, it starts with
val x = 5
instead of
val 1 = 2
:)
On Wed, Dec 21, 2011 at 12:16 PM, Daniel Sobral <dcsobral [at] gmail [dot] com> wrote:
Re: the ultimate scala cheat sheet
On 2011-12-21 16:59:14 -0600, Som Snytt said:
> Thanks for the link!
>
> But for some reason, it starts with
> val x = 5
> instead of
> val 1 = 2
OK, I'll ask. What does
val 1 = 2
do? or mean?
>
> :)
>
> On Wed, Dec 21, 2011 at 12:16 PM, Daniel Sobral
> wrote:
> You do know http://docs.scala-lang.org/cheatsheets/, I assume? Please,
> do contribute to it if you think there's things missing in it. You can
> contribute directly through this link:
> https://github.com/scala/scala.github.com/blob/gh-pages/cheatsheets/inde...
>
> On Wed, Dec 21, 2011 at 18:02, HamsterofDeath
> wrote:
> > hi community,
> >
> > i felt the desire to put together a scala cheat sheet. the reason is
> > that even after two years, i still find new features/tricks which don't
> > seem to be clearly documented - they exist, but are scattered across the
> > internet. there is already a cheat sheet, but it only covers a fraction
> > of what i am imagining here. there are some examples on scala-lang, but
> > i had to read them several times since they are not very clear. there
> > are some good blogs, but again, you have to look for them. i believe
> > that having a single, well structured pdf will make people more
> > comfortable with scala if they are new, should make it easier to
> > convince heretics to believe in scala :) and take away the fear of the
> > unknown complexity.
> >
> > it's probably going to be bigger than the usual cheat sheet so it's more
> > like a wallpaper, but splitting it up into subsections should help.
> > also, i want to focus on productivity boost features and keep it on a
> > level that a random java dev should be able to understand (i am thinking
> > about avoiding scary method signatures here and use java code as
> > examples of how this would look like in java or maybe other languages as
> > well)
> >
> > send your findings/knowledge to me/this list :)
> > i'll collect them and put them together.
>
>
>
> --
> Daniel C. Sobral
>
> I travel to the future all the time.
Re: Re: the ultimate scala cheat sheet
On Mon, Dec 26, 2011 at 10:57 AM, Sophie <itsme213 [at] hotmail [dot] com> wrote:
It does nothing, but it is a degenerate case of a pattern match. If you have
val (a,1) = ("hi",1)
you assign "hi" to the variable a (via pattern matching); if you
val (a,1) = ("hi",2)
then you get a MatchError (because 1 does not match 2). However, when there are no variables to match, Scala accepts the match syntax _but doesn't check the values_, so
val (1,2) = (1,3)
and even
val 1 = 2
silently do nothing instead of throwing a MatchError. Personally, I'd have changed the behavior so that variable-free matches still get tested, but for now this is the way it works.
--Rex
Re: the ultimate scala cheat sheet
Am 21.12.2011 23:59, schrieb Som Snytt:
Re: the ultimate scala cheat sheet
https://github.com/HamsterofDeath/scala.github.com/blob/gh-pages/cheatsheets/index.md
if you find an error, report it to me.
todos:
option
tuples
pattern matching, apply, unapply
objects, companion objects
abstract types
implicit conversions
Am 22.12.2011 07:40, schrieb HamsterofDeath:
Re: the ultimate scala cheat sheet
I wanted to report just a few typos I found:
def method(s:String)(s2:String) = s+" "+s2)
"=" means modify mutable collection xor assign new immutable collection to var
"comma separated numbers: " + List(1, 2, 3, 4, 5).fold("0")(_ + ", " + _) // Should be just "" instead of "0".
class CoVariant[-A] // Should be ContraVariant
class having a contravariant type parameter, meaning val CoVariant[SubClass] = coVariantWithSuperclass compiles
On Fri, Dec 23, 2011 at 6:36 PM, HamsterofDeath <h-star [at] gmx [dot] de> wrote:
Re: the ultimate scala cheat sheet
*check*
i really meant XOR since it cannot be both at the same time :). i'll rewrite it so it's clear to people not thinking like me.
probably more clear that way, yes.
*check*
*check*
Re: the ultimate scala cheat sheet
how many of you did know about
val List(head, rest@_*) = someList
?
in clojure i do this all the time and i had no idea i can do it in scala, too.
Am 24.12.2011 10:07, schrieb HamsterofDeath:
Re: the ultimate scala cheat sheet
More importantly you can do this for any sequence not just lists.
case Seq(head, tail @_*) => ....
On Dec 24, 2011 7:11 AM, "HamsterofDeath" <h-star [at] gmx [dot] de> wrote:Re: the ultimate scala cheat sheet
On Mon, Dec 26, 2011 at 11:17 AM, Josh Suereth wrote:
> More importantly you can do this for any sequence not just lists.
>
> case Seq(head, tail @_*) => ....
>
For what it's worth, this works with anything with unapply or
unapplySeq in this particular case.
You can use this to destructure anything with an unapply method, like
case classes, tuples, collections, options, and you can write your
own:
case class Foo(x: String, y: Int)
val foo = Foo("foo", 1)
val Foo(a, b) = foo // a: String = "foo", b: Int = 1
val tuple = (1, "test", 23L)
val (x, y, z) = tuple // x: Int = 1, y: String = "test", z: Long = 23L
val x: Option[String] = Some("test")
val Option(y) = x // y is now a string "test"
with most HList implementations (with appropriate imports):
val hlist = "test" :: false :: 10 :: HNil
val x :: y :: z :: HNil = hlist // x: String = "test", y: Boolean =
false, z: Int = 10
roll your own:
object Bippy {
def unapply(in: String): Option[Int] = try { Some(in.toInt) } catch
{ case _ => None }
}
val Bippy(i) = "123"
That's a terrible application of this feature, but it shows what you
can accomplish if you're a fan of sugar. Note that this will throw a
match error if you return None, so in this case any time there is an
exception with in.toInt.
You can even do it directly with instances:
// move a string to an optional int with a value if the int value of
the string matches the value passed into the constructor
class Bar(i: Int) {
def unapply(in: String): Option[Option[Int]] = try {
Some(Some(in.toInt).filter(_ == i)) } catch { case _ => Some(None) }
}
val bar = new Bar(10)
val bar(b) = "123" // = None: Option[String]
val bar(c) = "10" // = Some(10): Option[String]
val bar2 = new Bar(123)
val bar2(d) = "123" // = Some(123): Option[String]
val bar2(e) = "10" // = None: Option[String]
You can also stack destructurers to you hearts content:
val deepStructure = (Some("test"), Some(10), (Foo("foo", 1), Seq(1, 2, 3)))
val (Some(x), Some(y), (Foo(a, b), Seq(p, q, r))) = deepStructure //
x: String = "test", y: Int = 10, a: String = "foo", b: Int = 1, p: Int
= 1, q: Int = 2, r: Int = 3
Note that destructuring with :: as in
val a :: b :: c :: Nil = list
is actually deep destructuring with a case class (::) and is equivalent to
val ::(a, ::(b, ::(c, Nil))) = list
and the HList version uses the same sugary trick.
It's unfortunate that most HList implementations use the same case
class name (::) though, since it means you cannot destructure a List
when the HList class is imported. However, you can still build one.
Thanks, Chris
Re: the ultimate scala cheat sheet
Am 09.01.2012 20:31, schrieb Chris Reeves:
> On Mon, Dec 26, 2011 at 11:17 AM, Josh Suereth wrote:
>> More importantly you can do this for any sequence not just lists.
>>
>> case Seq(head, tail @_*) => ....
>>
> For what it's worth, this works with anything with unapply or
> unapplySeq in this particular case.
>
> You can use this to destructure anything with an unapply method, like
> case classes, tuples, collections, options, and you can write your
> own:
>
> case class Foo(x: String, y: Int)
> val foo = Foo("foo", 1)
> val Foo(a, b) = foo // a: String = "foo", b: Int = 1
>
> val tuple = (1, "test", 23L)
> val (x, y, z) = tuple // x: Int = 1, y: String = "test", z: Long = 23L
>
> val x: Option[String] = Some("test")
> val Option(y) = x // y is now a string "test"
>
> with most HList implementations (with appropriate imports):
> val hlist = "test" :: false :: 10 :: HNil
> val x :: y :: z :: HNil = hlist // x: String = "test", y: Boolean =
> false, z: Int = 10
>
> roll your own:
> object Bippy {
> def unapply(in: String): Option[Int] = try { Some(in.toInt) } catch
> { case _ => None }
> }
> val Bippy(i) = "123"
>
> That's a terrible application of this feature, but it shows what you
> can accomplish if you're a fan of sugar. Note that this will throw a
> match error if you return None, so in this case any time there is an
> exception with in.toInt.
>
> You can even do it directly with instances:
> // move a string to an optional int with a value if the int value of
> the string matches the value passed into the constructor
> class Bar(i: Int) {
> def unapply(in: String): Option[Option[Int]] = try {
> Some(Some(in.toInt).filter(_ == i)) } catch { case _ => Some(None) }
> }
> val bar = new Bar(10)
> val bar(b) = "123" // = None: Option[String]
> val bar(c) = "10" // = Some(10): Option[String]
> val bar2 = new Bar(123)
> val bar2(d) = "123" // = Some(123): Option[String]
> val bar2(e) = "10" // = None: Option[String]
>
> You can also stack destructurers to you hearts content:
> val deepStructure = (Some("test"), Some(10), (Foo("foo", 1), Seq(1, 2, 3)))
> val (Some(x), Some(y), (Foo(a, b), Seq(p, q, r))) = deepStructure //
> x: String = "test", y: Int = 10, a: String = "foo", b: Int = 1, p: Int
> = 1, q: Int = 2, r: Int = 3
>
> Note that destructuring with :: as in
> val a :: b :: c :: Nil = list
> is actually deep destructuring with a case class (::) and is equivalent to
> val ::(a, ::(b, ::(c, Nil))) = list
> and the HList version uses the same sugary trick.
> It's unfortunate that most HList implementations use the same case
> class name (::) though, since it means you cannot destructure a List
> when the HList class is imported. However, you can still build one.
>
> Thanks, Chris
>
the nested and works-on-instance-cases are worth noting, imho. it's
obvious when you think about it, but sometimes you don't...
Re: the ultimate scala cheat sheet
but i only succeeded if the matched sequence had the same type as the one in the case. other than toList anything, is there a more general way to match?
Am 26.12.2011 17:17, schrieb Josh Suereth:
Re: the ultimate scala cheat sheet
I didn't know you could do that (and don't have the repl to hand to
check) but is that not just a more complicated way of writing
val hd :: tl = someList
?
On 24 December 2011 12:11, HamsterofDeath wrote:
> added some more stuff.
> how many of you did know about
>
> val List(head, rest@_*) = someList
>
> ?
>
> in clojure i do this all the time and i had no idea i can do it in scala,
> too.
>
> Am 24.12.2011 10:07, schrieb HamsterofDeath:
>
> Am 24.12.2011 05:38, schrieb Tomás Lázaro:
>
> Hi great work!
>
> I wanted to report just a few typos I found:
>
> def method(s:String)(s2:String) = s+" "+s2)
>
>
> *check*
>
>
> "=" means modify mutable collection xor assign new immutable collection to
> var
>
>
> i really meant XOR since it cannot be both at the same time :). i'll rewrite
> it so it's clear to people not thinking like me.
>
>
> "comma separated numbers: " + List(1, 2, 3, 4, 5).fold("0")(_ + ", " + _)
> // Should be just "" instead of "0".
>
>
> probably more clear that way, yes.
>
>
> class CoVariant[-A] // Should be ContraVariant
>
> *check*
>
>
> class having a contravariant type parameter, meaning val CoVariant[SubClass]
> = coVariantWithSuperclass compiles
>
>
> *check*
>
>
> On Fri, Dec 23, 2011 at 6:36 PM, HamsterofDeath wrote:
>>
>> what i got so far
>>
>>
>> https://github.com/HamsterofDeath/scala.github.com/blob/gh-pages/cheatsh...
>>
>> if you find an error, report it to me.
>> todos:
>> option
>> tuples
>> pattern matching, apply, unapply
>> objects, companion objects
>> abstract types
>> implicit conversions
>>
>>
>>
>>
>> Am 22.12.2011 07:40, schrieb HamsterofDeath:
>>
>> i'll put that right at the top. what about val 1 = "hello number"?
>>
>> Am 21.12.2011 23:59, schrieb Som Snytt:
>>
>> Thanks for the link!
>>
>> But for some reason, it starts with
>> val x = 5
>> instead of
>> val 1 = 2
>>
>> :)
>>
>> On Wed, Dec 21, 2011 at 12:16 PM, Daniel Sobral
>> wrote:
>>>
>>> You do know http://docs.scala-lang.org/cheatsheets/, I assume? Please,
>>> do contribute to it if you think there's things missing in it. You can
>>> contribute directly through this link:
>>>
>>> https://github.com/scala/scala.github.com/blob/gh-pages/cheatsheets/inde...
>>>
>>> On Wed, Dec 21, 2011 at 18:02, HamsterofDeath wrote:
>>> > hi community,
>>> >
>>> > i felt the desire to put together a scala cheat sheet. the reason is
>>> > that even after two years, i still find new features/tricks which don't
>>> > seem to be clearly documented - they exist, but are scattered across
>>> > the
>>> > internet. there is already a cheat sheet, but it only covers a fraction
>>> > of what i am imagining here. there are some examples on scala-lang, but
>>> > i had to read them several times since they are not very clear. there
>>> > are some good blogs, but again, you have to look for them. i believe
>>> > that having a single, well structured pdf will make people more
>>> > comfortable with scala if they are new, should make it easier to
>>> > convince heretics to believe in scala :) and take away the fear of the
>>> > unknown complexity.
>>> >
>>> > it's probably going to be bigger than the usual cheat sheet so it's
>>> > more
>>> > like a wallpaper, but splitting it up into subsections should help.
>>> > also, i want to focus on productivity boost features and keep it on a
>>> > level that a random java dev should be able to understand (i am
>>> > thinking
>>> > about avoiding scary method signatures here and use java code as
>>> > examples of how this would look like in java or maybe other languages
>>> > as
>>> > well)
>>> >
>>> > send your findings/knowledge to me/this list :)
>>> > i'll collect them and put them together.
>>>
>>>
>>>
>>> --
>>> Daniel C. Sobral
>>>
>>> I travel to the future all the time.
>>
>>
>>
>>
>
>
>
Re: the ultimate scala cheat sheet
in that special case, a :: tl is simpler, yes.
but:
val List(_, a,b,_,tl@_*) = ... // discard the head and 4th element
val Vector(...) = ..... // works also on other collection types
both not possible the :: way
Am 24.12.2011 14:37, schrieb Alec Zorab:
> I didn't know you could do that (and don't have the repl to hand to
> check) but is that not just a more complicated way of writing
>
> val hd :: tl = someList
>
> ?
>
> On 24 December 2011 12:11, HamsterofDeath wrote:
>> added some more stuff.
>> how many of you did know about
>>
>> val List(head, rest@_*) = someList
>>
>> ?
>>
>> in clojure i do this all the time and i had no idea i can do it in scala,
>> too.
>>
>> Am 24.12.2011 10:07, schrieb HamsterofDeath:
>>
>> Am 24.12.2011 05:38, schrieb Tomás Lázaro:
>>
>> Hi great work!
>>
>> I wanted to report just a few typos I found:
>>
>> def method(s:String)(s2:String) = s+" "+s2)
>>
>>
>> *check*
>>
>>
>> "=" means modify mutable collection xor assign new immutable collection to
>> var
>>
>>
>> i really meant XOR since it cannot be both at the same time :). i'll rewrite
>> it so it's clear to people not thinking like me.
>>
>>
>> "comma separated numbers: " + List(1, 2, 3, 4, 5).fold("0")(_ + ", " + _)
>> // Should be just "" instead of "0".
>>
>>
>> probably more clear that way, yes.
>>
>>
>> class CoVariant[-A] // Should be ContraVariant
>>
>> *check*
>>
>>
>> class having a contravariant type parameter, meaning val CoVariant[SubClass]
>> = coVariantWithSuperclass compiles
>>
>>
>> *check*
>>
>>
>> On Fri, Dec 23, 2011 at 6:36 PM, HamsterofDeath wrote:
>>> what i got so far
>>>
>>>
>>> https://github.com/HamsterofDeath/scala.github.com/blob/gh-pages/cheatsh...
>>>
>>> if you find an error, report it to me.
>>> todos:
>>> option
>>> tuples
>>> pattern matching, apply, unapply
>>> objects, companion objects
>>> abstract types
>>> implicit conversions
>>>
>>>
>>>
>>>
>>> Am 22.12.2011 07:40, schrieb HamsterofDeath:
>>>
>>> i'll put that right at the top. what about val 1 = "hello number"?
>>>
>>> Am 21.12.2011 23:59, schrieb Som Snytt:
>>>
>>> Thanks for the link!
>>>
>>> But for some reason, it starts with
>>> val x = 5
>>> instead of
>>> val 1 = 2
>>>
>>> :)
>>>
>>> On Wed, Dec 21, 2011 at 12:16 PM, Daniel Sobral
>>> wrote:
>>>> You do know http://docs.scala-lang.org/cheatsheets/, I assume? Please,
>>>> do contribute to it if you think there's things missing in it. You can
>>>> contribute directly through this link:
>>>>
>>>> https://github.com/scala/scala.github.com/blob/gh-pages/cheatsheets/inde...
>>>>
>>>> On Wed, Dec 21, 2011 at 18:02, HamsterofDeath wrote:
>>>>> hi community,
>>>>>
>>>>> i felt the desire to put together a scala cheat sheet. the reason is
>>>>> that even after two years, i still find new features/tricks which don't
>>>>> seem to be clearly documented - they exist, but are scattered across
>>>>> the
>>>>> internet. there is already a cheat sheet, but it only covers a fraction
>>>>> of what i am imagining here. there are some examples on scala-lang, but
>>>>> i had to read them several times since they are not very clear. there
>>>>> are some good blogs, but again, you have to look for them. i believe
>>>>> that having a single, well structured pdf will make people more
>>>>> comfortable with scala if they are new, should make it easier to
>>>>> convince heretics to believe in scala :) and take away the fear of the
>>>>> unknown complexity.
>>>>>
>>>>> it's probably going to be bigger than the usual cheat sheet so it's
>>>>> more
>>>>> like a wallpaper, but splitting it up into subsections should help.
>>>>> also, i want to focus on productivity boost features and keep it on a
>>>>> level that a random java dev should be able to understand (i am
>>>>> thinking
>>>>> about avoiding scary method signatures here and use java code as
>>>>> examples of how this would look like in java or maybe other languages
>>>>> as
>>>>> well)
>>>>>
>>>>> send your findings/knowledge to me/this list :)
>>>>> i'll collect them and put them together.
>>>>
>>>>
>>>> --
>>>> Daniel C. Sobral
>>>>
>>>> I travel to the future all the time.
>>>
>>>
>>>
>>
>>
Re: the ultimate scala cheat sheet
var _ :: a :: b :: _ :: tl = ...
Well, one out of two is not bad. And, by the way, I did know it. :-)
Speaking of "a xor b", write it "either a or b".
--
Daniel C. Sobral
I travel to the future all the time.
Re: the ultimate scala cheat sheet
Am 24.12.2011 21:14, schrieb Daniel Sobral: even this works: val _ :: _ = List(1,2)
i'll mention it in the "obvious" section right after val 1 = 2
Re: the ultimate scala cheat sheet
On Wed, Dec 21, 2011 at 20:59, Som Snytt wrote:
> Thanks for the link!
>
> But for some reason, it starts with
> val x = 5
> instead of
> val 1 = 2
We assume "val 1 = 2" is so basic and obvious that no cheat on it is
required. ;-)
Re: the ultimate scala cheat sheet
i didn't know i could change it directly. this cheat sheet will be
extended then :)
Am 21.12.2011 21:16, schrieb Daniel Sobral:
> You do know http://docs.scala-lang.org/cheatsheets/, I assume? Please,
> do contribute to it if you think there's things missing in it. You can
> contribute directly through this link:
> https://github.com/scala/scala.github.com/blob/gh-pages/cheatsheets/inde...
>
> On Wed, Dec 21, 2011 at 18:02, HamsterofDeath wrote:
>> hi community,
>>
>> i felt the desire to put together a scala cheat sheet. the reason is
>> that even after two years, i still find new features/tricks which don't
>> seem to be clearly documented - they exist, but are scattered across the
>> internet. there is already a cheat sheet, but it only covers a fraction
>> of what i am imagining here. there are some examples on scala-lang, but
>> i had to read them several times since they are not very clear. there
>> are some good blogs, but again, you have to look for them. i believe
>> that having a single, well structured pdf will make people more
>> comfortable with scala if they are new, should make it easier to
>> convince heretics to believe in scala :) and take away the fear of the
>> unknown complexity.
>>
>> it's probably going to be bigger than the usual cheat sheet so it's more
>> like a wallpaper, but splitting it up into subsections should help.
>> also, i want to focus on productivity boost features and keep it on a
>> level that a random java dev should be able to understand (i am thinking
>> about avoiding scary method signatures here and use java code as
>> examples of how this would look like in java or maybe other languages as
>> well)
>>
>> send your findings/knowledge to me/this list :)
>> i'll collect them and put them together.
>
>
Re: the ultimate scala cheat sheet
On Wed, Dec 21, 2011 at 18:38, HamsterofDeath wrote:
> i didn't know i could change it directly. this cheat sheet will be
> extended then :)
The whole docs.scala-lang.org site was intended to be easily
contributed to. Well, almost all of it. :-)
>
> Am 21.12.2011 21:16, schrieb Daniel Sobral:
>> You do know http://docs.scala-lang.org/cheatsheets/, I assume? Please,
>> do contribute to it if you think there's things missing in it. You can
>> contribute directly through this link:
>> https://github.com/scala/scala.github.com/blob/gh-pages/cheatsheets/inde...
>>
>> On Wed, Dec 21, 2011 at 18:02, HamsterofDeath wrote:
>>> hi community,
>>>
>>> i felt the desire to put together a scala cheat sheet. the reason is
>>> that even after two years, i still find new features/tricks which don't
>>> seem to be clearly documented - they exist, but are scattered across the
>>> internet. there is already a cheat sheet, but it only covers a fraction
>>> of what i am imagining here. there are some examples on scala-lang, but
>>> i had to read them several times since they are not very clear. there
>>> are some good blogs, but again, you have to look for them. i believe
>>> that having a single, well structured pdf will make people more
>>> comfortable with scala if they are new, should make it easier to
>>> convince heretics to believe in scala :) and take away the fear of the
>>> unknown complexity.
>>>
>>> it's probably going to be bigger than the usual cheat sheet so it's more
>>> like a wallpaper, but splitting it up into subsections should help.
>>> also, i want to focus on productivity boost features and keep it on a
>>> level that a random java dev should be able to understand (i am thinking
>>> about avoiding scary method signatures here and use java code as
>>> examples of how this would look like in java or maybe other languages as
>>> well)
>>>
>>> send your findings/knowledge to me/this list :)
>>> i'll collect them and put them together.
>>
>>
>