Layla  Gerhold

Layla Gerhold

1596900300

The Practical Difference Between Abstract Classes and Traits in Scala

This short article will compare abstract classes and traits as means of inheritance. This is for the beginner Scala programmer who is just getting started with Scala’s inheritance model. If you’re trying to figure out which is the best way to create OO-style type hierarchies and abstract classes seem too similar to traits, this article is for you.

#java #tutorial #scala #object-oriented programming #abstract classes

What is GEEK

Buddha Community

The Practical Difference Between Abstract Classes and Traits in Scala
Layla  Gerhold

Layla Gerhold

1596900300

The Practical Difference Between Abstract Classes and Traits in Scala

This short article will compare abstract classes and traits as means of inheritance. This is for the beginner Scala programmer who is just getting started with Scala’s inheritance model. If you’re trying to figure out which is the best way to create OO-style type hierarchies and abstract classes seem too similar to traits, this article is for you.

#java #tutorial #scala #object-oriented programming #abstract classes

Abstract class & Abstract method in C# | OOP in C# Part-24

https://youtu.be/vonwoaUl0Hw

#oop #abstract #abstract method #abstract class #what is abstract

Yashi Tyagi

1617449307

CA Classes - Best CA Classes Online

Chartered Accountancy course requires mental focus & discipline, coaching for CA Foundation, CA Inter and CA Finals are omnipresent, and some of the best faculty’s classes have moved online, in this blog, we are going to give the best way to find online videos lectures, various online websites provide the CA lectures, Smartnstudy one of the best site to CA preparation, here all faculty’s video lecture available.

check here : ca classes

#ca classes online #ca classes in delhi #ca classes app #ca pendrive classes #ca google drive classes #best ca classes online

Myrl  Prosacco

Myrl Prosacco

1594453980

A Beginner's Guide to Scala 3.0

**Dotty, **a comprehensive name for all the things that are being added to Scala 3.0 has been a topic of discussion in the Scala community for the last four years. With all the promises and progress, The time for the release is very near. We can expect a release by the end of the year. In this post, we will get a teaser of what changes to expect from Dotty as well as some of the new changes in the major release. At the end of the post, we will see how we can quickly start with the Dotty compiler and example code.

Screenshot from 2020-06-04 08-41-20

What changes to expect from Dotty?

If you would ask, “Is Scala 3.0 a new language”, Martin Ordersky says “yes Or no” in “A tour of Dotty.” He has reasons for it. If you ask me, I would say yes!! It has a lot of new features.

  • If you are a beginner, and only starting with Scala 3, you will find the new features as a new concept that was not part of the old Scala.
  • Below snippet is a poll depicting the favorite changes for beginners in Scala 3.0. which was shared by Martin Ordersky in the last edition of ScalaDays.

Screenshot from 2020-06-04 08-48-09

  • However, it does not end here. There are more changes which you will see in the next section.
  • If you are at an intermediate level in scala and already familiar with the constructs of the language, you will see some of the features which are removed and no longer supported. We will see those in detail in the upcoming sections.
  • If you are a Scala expert and FP Enthusiast, there is a list of changes for you as well such as, **type-level derivation, match types, implicit function types, Metaprogramming **to name a few.
  • These changes are shared in “A tour of Dotty” by Martin Ordersky in the last edition of the ScalaDays.

Breaking Changes!

What do we mean by breaking changes? Those changes which are not going to be supported and compiling them in the newer version will require a re-write of the source in either a new way or to be removed. There are some features that are considered to have been pain points performance-wise or creating unnecessary complexity that is going to removed from Scala 3.0.

At a preview level here is the list of breaking changes:

**Macro:  **One of the biggest breaking change is Macros. The newer version of Scala includes a newer macros-system and Experimental Macro from Scala version 2.13 will not work in 3.0 and will have to be re-written.

**22-Arity: **The limits of 22 for the maximal number of parameters of function types and the maximal number of fields in tuple types have been dropped.

**And many more features. **Here is the list of all the breaking changes you should go through if you think you will be porting your code at some point in time.

An exhaustive list of Dropped Features is given below: 

#dotty #scala #scala days #beginners #dotty #functional programming in scala #scala 3

Myrl  Prosacco

Myrl Prosacco

1594461240

Use of Either in Scala

In this blog, we are going to see the use of Either in scala.

We use Options in scala but why do we want to go for Either?

Either is a better approach in the respect that if something fails we can track down the reason, which in Option None case is not possible.

We simply pass None but what is the reason we got None instead of Some. We will see how to tackle this scenario using Either.

Either[Left, Right]

None is similar to Left which signifies Failure and Some is similar to Right which signifies Success.

Let’s see with help of an example:

def returnEither(value: String): Either[NumberFormatException, Int] =
{
try {
Right(value.toInt)
} catch {
case ex: NumberFormatException => Left(ex)
}
}
returnEither("abc").map(x => println(x))

It will not print anything, Either is right biased and returnEither(“abc”) gives Left(java.lang.NumberFormatException: For input string: “abc”)

Now let’s call it on Right value.

returnEither("1").map(x => println(x))

It will print 1. Yes, it is right biased as the map works on Either.right. What if I want to call the map on left?

returnEither("abc").left.map(x => println(x))

It will print** java.lang.NumberFormatException: For input string: “abc”.**

Using Match case with Either

returnEither("1") match
{
case Right(value) => println(s"Right value: $value")
case Left(ex: NumberFormatException) => println(ex)
}

It will print Right value: 1

Extract value from Either

Let’s say we want to extract left value from Either.

println(returnEither("abc").left)

will print LeftProjection(Left(java.lang.NumberFormatException: For input string: “abc”))

println(returnEither("1").left)

will print LeftProjection(Right(1)).

println(returnEither("abc").left.get)

will give java.lang.NumberFormatException: For input string: “abc”.

println(returnEither("1").left.get)

will give: Exception in thread “main” java.util.NoSuchElementException: Either.left.get on Right

Oops. It had right value.

We can use getOrElse or fold for default value.

#scala ##use of either ##use of either in scala #either #scala