Wednesday, January 29, 2020
Tuesday, January 28, 2020
How do implicit work in Spark/Scala
Scala has a way to add methods to existing classes, like extension method in Kotlin (and C# as I remember), but does it in a different way, through implicits.
To add the method to existing class, you first create implicit class:
object StringImplicits {
implicit class StringUtils(s: String) {
def someCoolMethod = println("Yooo")
}
}
object Application extends App {
import StringImplicits._
val s = "Hello"
s.someCoolMethod
}
You import this
StringUtils
and can call someCoolMethod
on instance of String
Notice that
StringUtils
class takes String
as a constuctor param.
When calling some method on
String
, scala compiler first looks this method in String
class.
If it does not find it, it will look imported implicit classes which take
String
param.
If found, it calls the method from that class.
If no such class found, it will raise the error.
Thursday, January 2, 2020
How to Install Guest Additions (Enable Fullscreen, Shared Clipboard, Drag & Drop) on Ubuntu 18.04 LTS in VirtualBox?
Step 1: Update Package Lists
sudo apt update
Step 2: Upgrade Packages
sudo apt upgrade
Step 3: Click on 'close' button at the top right, and then click on 'Power Off the Machine'.
Step 4: Click on 'ok' button.
Step 5: Go to 'Settings', and then 'General'. Click on 'Advanced' tab.
Step 6: Enable Bidirectional in shared clipboard, and Drag 'n' drop. After that start your ubuntu 18.04 LTS, and login.
Step 7: Install Dependencies Required for Guest Additions, open terminal and run the command below:-
sudo apt install build-essential dkms linux-headers-$(uname -r)
Step 8: After installation of dependencies, click on 'Devices' in top menu, and then click on 'Insert Guest Additions CD Image'. After that, click on run button. Install it.
Step 9: Install virtualbox-guest-dkms to enable shared clipboard and Drag and Drop Features. After that, restart ubuntu.
Subscribe to:
Posts (Atom)
Recent Post
Databricks Delta table merge Example
here's some sample code that demonstrates a merge operation on a Delta table using PySpark: from pyspark.sql import SparkSession # cre...
-
OpenVPN 2.4 also became the default version your connections use. OpenVPN 2.4 adds many security and performance improvements. Because OpenV...
-
Step 1: we have check the installed sbt version . if sbt installed version on out laptop is say : 1.3.13 [info] welcome to sbt 1.3.13 ...
-
REST (Representational State Transfer) is style of architecture that enables development of loosely coupled systems by using the HTTP prot...