r/scalastudygroup • u/[deleted] • Nov 17 '15
r/scalastudygroup • u/AkashDaniel • Mar 03 '16
Package of Scala and Python to implement Programming Skills on Apache Spark
r/scalastudygroup • u/martino_k • May 25 '20
12 Ways on How to Improve Your Learning Process
r/scalastudygroup • u/[deleted] • Sep 15 '21
Preptember - Prepare For HacktoberFest 2021
r/scalastudygroup • u/juror-number-8 • Oct 15 '15
Week 1 Day 4: Control Structures
The topics today are pretty straight forward. Anyone with basic programming language knowledge might already know most of it. The standout among these is the For loop.
If
While
For
Foreach
The foreach method takes a function as an argument. The function you define should take an element as an input parameter, and should not return anything. The input parameter type should match the type stored in the collection. As foreach executes, it passes one element at a time from the collection to your function until it reaches the last element in the collection.
The foreach method applies your function to each element of the collection, but it doesn’t return a value. Because it doesn’t return anything, it’s said that it’s used for its "side effect."
As an example, a common use of foreach is to output information:
scala> val x = Vector(1, 2, 3)
x: scala.collection.immutable.Vector[Int] = Vector(1, 2, 3)
scala> x.foreach((i: Int) => println(i))
1
2
3
That’s the longhand way of writing that code. For most expressions, Scala can infer the type, so specifying i: Int isn’t necessary:
args.foreach(i => println(i))
You can further shorten this expression by using the ubiquitous underscore wildcard character instead of using a temporary variable:
args.foreach(println(_))
In a situation like this, where a function literal consists of one statement that takes a single argument, it can be condensed to this form:
args.foreach(println)
For a simple case like this, the syntax in the last example is typically used.
Extract from Scala cookbook
r/scalastudygroup • u/juror-number-8 • Oct 12 '15
Week 1 Day 1: Introduction to Scala
What is Scala and Why scala?
Why should I learn Scala?(Blog)
What is the purpose of Scala?(Stackoverflow)
Why Scala?(Blog)
Scala or Java? Exploring myths and facts(Blog)
Oops.add(functional)
Object-Oriented Meets Functional(Slide)
Scala as a Functional OO Hybrid(Blog)
Scala and JVM
The best thing about Java is not the language but the JVM. A JVM is a fine piece of machinery, and the Hotspot team has done a good job in improving its performance over the years. Being a JVM language, Scala integrates well with Java and its ecosystem, including tools, libraries, and IDEs. Now most of the IDEs ship with the Scala plug-in so that you can build, run, and test Scala applications inside the IDE. To use Scala you don’t have to get rid of all the investments you’ve made in Java so far. Instead you can reuse them and keep your ROI coming.
Scala compiles to Java byte code, and at the byte-code level you can’t distinguish between Java code and Scala code. They’re the same. You could use the Java class file disassembler javap to disassemble Scala byte code as you could for Java classes.
Another advantage of running Scala on a JVM is that it can harness all the benefits of JVM-like performance and stability out of the box. And being a statically typed language, Scala programs run as fast as Java programs.
extract from Scala In Action
Installation
Scala Environment Setup(Tutorial)
REPL(Read-Evaluate-Print Loop)
Scala Interactive Interpreter(Blog: Check the REPL segment)
12 Things, Part 1: The Scala REPL
Ammonite: Scala REPL alternative(github)
r/scalastudygroup • u/juror-number-8 • Oct 18 '15
Week 1 Day 6: Class & Object
Constructors
How to create multiple class constructors in Scala
TOP 5 THINGS TO KNOW ABOUT CONSTRUCTORS IN SCALA
Abstract Classes
scala abstract classes - the basics
What is the advantage of using abstract classes instead of traits?
Nested Classes
how to create an instance of a nested case class
Objects and companion objects
r/scalastudygroup • u/porl • Sep 13 '17
Trying to understand how to solve a problem with reactive streams
Hi all I'm not sure where to ask this question but I'm trying to learn the basic ideas on how to solve a problem using reactive streams or similar.
Basically I have a device with inputs and a stream output. To simplify you can imagine the device has one control input (say, "gain") and one data stream output ("signal").
My main confusion is in how to process the stream output. I need to monitor the signal for peaks in the wave, after applying some basic noise filtering and so forth. Once I detect a potential peak, I need to determine the "true" height of the peak and add that to a list of peak values. This all needs to be done live as the stream continues for an arbitrary amount of time (the old stream data can be discarded as the window moves along).
I'm mainly confused as to how to take a stream, watch for the possibility of the start of a peak, "record" that until it either fails or determines it is a real peak, send that section of the stream to a peak height function, then send that data to a list of peaks for display and further processing.
The control input is updated according to other information obtained from the stream input, however I think I could work out the process of that from the details of the stream processing section.
The old system was programmed in LabView and is a mess of wires and a nightmare to maintain. I'd like to rework it in a more sane language and the biggest stumbling block I have is how to get a waveform signal into a list of peak height values in realtime.
I hope this is an okay place to ask this. I tried on the /r/scala subreddit a while back but of course that is more for scala news and so forth.
r/scalastudygroup • u/juror-number-8 • Oct 13 '15
Week 1 Day 2: Variables, Functions & Literals
var vs val
Scala Variables (tutorial)
What is the difference between a var and val definition in Scala? (Stackoverflow)
Function definition
Learning Scala – Methods (Blog)
Named parameters
Named Parameters (Scala docs)
Scala functions - named arguments and default arguments (Blog)
Anonymous functions
Anonymous Function Syntax Anonymous Functions (tutorial)
Literals
Scala Data Types (tutorial)
r/scalastudygroup • u/juror-number-8 • Oct 14 '15
Week 1 Day 3: List, Tuple & Array
List
Scala List class examples (Blog)
Five ways to create a Scala List (Blog)
Scala list concatenation - ::: vs ++ (Stackoverflow)
When and why should I use a List instead of a ListBuffer? (Quora)
Difference between MutableList and ListBuffer (Stackoverflow)
Tuples
Scala Goodness: Tuples (Blog)
Scala tuple examples and syntax (Blog)
Why is Scala's syntax for tuples so unusual? (Stackoverflow)
Scala Tuple length (Stackoverflow)
Array
Different ways to create and update an Array (Blog)
Array Basics (video)
Compare two arrays in scala (Stackoverflow)
r/scalastudygroup • u/juror-number-8 • Oct 07 '15
Topics for Week 1
Hi everyone,
After going through a lot of reading materials I have collected, I have narrowed the topics that we can learn for the first week. For the people who are already halfway into learning scala, these may be redundant but you can help us by sharing things that we might have missed.
Following the topics
Day 1 - Introduction(I hate it too, but has to be done)
What is Scala
Why scala
Oops.add(functional)
Scala and JVM
Installation
REPL
Day 2 - Variables, Functions & Literals
var vs val
Function definition
Named parameters
Anonymous functions
Literals
Day 3 - List, Tuple & Array
Day 4 - Control Structures
If
While
For
Foreach
Day 5 - Pattern Matching
A Simple Match
Matching on Type
Matching on Sequences
Matching on Tuples (and Guards)
Matching on Case Classes
Matching on Regular Expressions
Binding Nested Variables in Case Clauses
Day 6 - Class & Object
Constructors
Abstract Classes
Nested Classes
Objects and companion objects
Day 7 - Case Class
If you think, I have not covered any topic, please let me know in the comments I'll add them here or will add them in the following weeks.
Suggestions are most welcome.
r/scalastudygroup • u/juror-number-8 • Oct 06 '15
println("hello world!")
Hello Everyone,
I have created this subreddit to help us learn scala as group and at the same time capture whatever we are doing, so that it can helpful to others who are joining us later.
I am thinking of creating a plan for us to move forward. Later this day, I'll list down all the topics that we will be covering in the following weeks. Everyday, I will create a post with a topic from the list and few links which explains the topic in detail. Anyone can post more links to the same post as comments. We can also use the comments for clarifying our doubts.
During weekends, I'll add a couple of extra posts as assignment for us to get our hands dirty with the topics that were covered during the week.
Towards the end, lets do a project(or a few) as a group to cement our knowledge base and give back to the scala community.
Meanwhile, I'll interact with the moderators of /r/scala and will try to get a couple of scala experts to oversee things around here and help us with our doubts and clarifications.
Please introduce yourself in the comments(atleast languages known, timezone) and feel free to throw in suggestions.
r/scalastudygroup • u/[deleted] • Sep 02 '21
My Scala Notes - Scala For Beginners - Crash Course - Part 3
My notes from 3 months back when I started learning scala on functional programming.
https://blog.codekaro.info/scala-for-beginners-crash-course-part-3
r/scalastudygroup • u/[deleted] • Sep 14 '21
Scala Vs Python Syntax Cheat Sheet
r/scalastudygroup • u/[deleted] • Sep 06 '21
Scala For Beginners - Crash Course - Part 4
r/scalastudygroup • u/[deleted] • Sep 13 '21
Scala For Beginners - Crash Course - Part 5
r/scalastudygroup • u/[deleted] • Feb 14 '21
Why returning 0.0 for Square area?
Why is Rectangle area working but not Square area? I have tried this in my worksheet, repl, and Scastie. All return 0.0.
From Essential Scala
trait Shape {
def sides: Int
def perimeter: Double
def area: Double
}
sealed trait Rectangular extends Shape {
def width: Double
def height: Double
val sides = 4
override val perimeter = 2*width + 2*height
override val area = width*height
}
case class Square(size: Double) extends Rectangular {
val width = size
val height = size
}
case class Rectangle(
val width: Double,
val height: Double
) extends Rectangular
val r = Rectangle(4,8)
r.area
val s = Square(8)
s.area
s.width
s.heightr.area is returning 32.0: Double
s.area returning 0.0: Double
s.width 8.0: Double
s.height: 8.0 Double
r/scalastudygroup • u/Algomancer • Oct 05 '16
A really simple Full Stack Scala Starter with Binding.scala and Play 2.5 [X-Post /r/scala]
r/scalastudygroup • u/rathereasy • Oct 07 '16
Looking for a paid tutor
Hello everyone, I'm an experienced O'Caml programmer and I'm interested in learning Scala. Reading through learning material intended for beginners is very time consuming and uninteresting. I have a very specific project in mind and I need someone to answer my questions through text chat. More specifically, I'd like to learn how to convert objects to and from JSON and how to create a very simple HTTP server.
r/scalastudygroup • u/pedrorijo91 • Mar 26 '16
How to Correctly parse JSON to Scala case class?
I saw this question on SO: http://stackoverflow.com/questions/36202938/scala-play-reads-parse-nested-json/36210676
From times to times I find myself in the same position, having some problems correctly parsing JSON to some Scala case class (often with Sequences or DateTime).
So, how could one answer to the question on SO? The problem is in parsing the JSON Array of 'Friends' into a Sequence of 'ids' (Longs).
Using a case class for the 'Friend' it would be easy: https://gist.github.com/pedrorijo91/e8b89b0ae7a1e8d16938
But what about without the case class? How would the Response reader be like?
2) Another typical use case I face is when the JSON contains a long (let's say json = { "date": 1458860074 }, and I want to map it to a DateTime using the constructor that receives the long
Note: org.joda.time.DateTime
I would expect something like this to work:
case class Exp(datetime: DateTime) object Exp { implicit val reader: Reads[Exp] = (JsPath \ "date").read[Long].map(d => new DateTime(d)) (Exp.apply _) }
But I get a:
type mismatch; found : org.joda.time.DateTime => plugins.results.traits.config.Exp required: play.api.libs.json.Reads[?]
3) Is there any good info on this json parse subject? I found https://www.playframework.com/documentation/2.4.x/ScalaJson but it doesn't seem very clear to me on how to do such not-so-basic operations
Thanks