leverich / swiftislikescala

Swift is a lot like scala
MIT License
95 stars 25 forks source link

Fixed missing arg #3

Closed freekh closed 10 years ago

freekh commented 10 years ago

Hi! I like this comparison! I think I found a minor issue, corrected by this PR.

Also, how about adding a pattern match part as well? I guess that is the way you typically check types and downcast (at least in Scala?). I do not have the Beta 3 so cannot try it out but I guess it would be something like:

var movieCount = 0
var songCount = 0

for (item <- library) {
  item match {
    case movie: Movie =>
      movieCount += 1
      println(s"Movie: '${movie.name}', dir. ${movie.director}")
    case song: Song =>
      songCount += 1
      println(s"Song: '${song.title}'")
  }
}
var movieCount = 0
var songCount = 0

for item in library {
  switch item {
    case let movie as Movie:
      ++movieCount
      println("Movie: '\(movie.name)', dir. \(movie.director)")
    case let song as Song:
      ++songCount
      println("Song: '\(song.title)'")
  }
}
leverich commented 10 years ago

Oops, thanks!

Lovely pattern match example! I'll incorporate it.

freekh commented 10 years ago

:) cool

On July 8, 2014 7:56:26 PM CEST, Jacob Leverich notifications@github.com wrote:

Oops, thanks!

Lovely pattern match example! I'll incorporate it.


Reply to this email directly or view it on GitHub: https://github.com/leverich/swiftislikescala/pull/3#issuecomment-48375877

Sent from my Android device with K-9 Mail. Please excuse my brevity.

leverich commented 10 years ago

Hey Fredrik, I got around to adding the pattern match example. Thanks!

Also, I'm going to start compiling comparisons to more "idiomatic" usage of Scala to show along-side the rote translations from swift -> scala. If you have any suggestions, feel free to shoot them this way. Look at the "tuple return" comparison as an example.

Cheers, -jacob

On Tue, Jul 8, 2014 at 10:58 AM, Fredrik Ekholdt notifications@github.com wrote:

:) cool

On July 8, 2014 7:56:26 PM CEST, Jacob Leverich notifications@github.com wrote:

Oops, thanks!

Lovely pattern match example! I'll incorporate it.


Reply to this email directly or view it on GitHub: https://github.com/leverich/swiftislikescala/pull/3#issuecomment-48375877

Sent from my Android device with K-9 Mail. Please excuse my brevity.

— Reply to this email directly or view it on GitHub https://github.com/leverich/swiftislikescala/pull/3#issuecomment-48376160 .

freekh commented 10 years ago

Yeah, I like that! Swift is like verbose and imperative Scala :) I wish Swift could have been expression based as well (most statement "returns" a value) - this is one of the features of Scala which makes code much easier to read (for my eyes at least).