-
Notifications
You must be signed in to change notification settings - Fork 0
/
Introduction to Scala Programming.html
43 lines (41 loc) · 123 KB
/
Introduction to Scala Programming.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html>
<head>
<meta name="databricks-html-version" content="1">
<title>Introduction to Scala Programming - Databricks</title>
<meta charset="utf-8">
<meta name="google" content="notranslate">
<meta name="robots" content="nofollow">
<meta http-equiv="Content-Language" content="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF8">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700">
<link rel="stylesheet" type="text/css" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/lib/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/lib/jquery-ui-bundle/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/css/main.css">
<link rel="stylesheet" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/css/print.css" media="print">
<link rel="icon" type="image/png" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/img/favicon.ico"/>
<script>window.settings = {"enableSshKeyUI":false,"defaultInteractivePricePerDBU":0.4,"enableOnDemandClusterType":true,"enableAutoCompleteAsYouType":[],"devTierName":"Community Edition","enableJobsPrefetching":true,"workspaceFeaturedLinks":[{"linkURI":"https://docs.databricks.com/index.html","displayName":"Documentation","icon":"question"},{"linkURI":"https://docs.databricks.com/release-notes/product/index.html","displayName":"Release Notes","icon":"code"},{"linkURI":"https://docs.databricks.com/spark/latest/training/index.html","displayName":"Training & Tutorials","icon":"graduation-cap"}],"enableClearStateFeature":false,"dbcForumURL":"http://forums.databricks.com/","enableProtoClusterInfoDeltaPublisher":true,"maxCustomTags":45,"enableInstanceProfilesUIInJobs":true,"nodeInfo":{"node_types":[{"support_ssh":false,"spark_heap_memory":4800,"instance_type_id":"r3.2xlarge","spark_core_oversubscription_factor":8.0,"node_type_id":"dev-tier-node","description":"Community Optimized","support_cluster_tags":false,"container_memory_mb":6000,"node_instance_type":{"instance_type_id":"r3.2xlarge","provider":"AWS","compute_units":26.0,"number_of_ips":15,"local_disks":1,"reserved_compute_units":3.64,"memory_mb":62464,"num_cores":8,"reserved_memory_mb":4800},"memory_mb":6144,"is_hidden":false,"category":"Community Edition","num_cores":0.88,"support_ebs_volumes":false,"is_deprecated":false}],"default_node_type_id":"dev-tier-node"},"enableClusterAcls":true,"notebookRevisionVisibilityHorizon":999999,"enableTableHandler":true,"maxEbsVolumesPerInstance":10,"isAdmin":true,"deltaProcessingBatchSize":1000,"enableLargeResultDownload":true,"zoneInfos":[{"id":"us-west-2c","isDefault":true},{"id":"us-west-2b","isDefault":false},{"id":"us-west-2a","isDefault":false}],"enableCustomSpotPricingUIByTier":false,"enableEBSVolumesUIForJobs":true,"enablePublishNotebooks":true,"enableMaxConcurrentRuns":true,"enableJobAclsConfig":false,"enableFullTextSearch":false,"enableElasticSparkUI":false,"enableNewClustersCreate":true,"clusters":true,"allowRunOnPendingClusters":true,"fileStoreBase":"FileStore","enableSshKeyUIInJobs":true,"enableDetachAndAttachSubMenu":false,"configurableSparkOptionsSpec":[{"keyPattern":"spark\\.kryo(\\.[^\\.]+)+","valuePattern":".*","keyPatternDisplay":"spark.kryo.*","valuePatternDisplay":"*","description":"Configuration options for Kryo serialization"},{"keyPattern":"spark\\.io\\.compression\\.codec","valuePattern":"(lzf|snappy|org\\.apache\\.spark\\.io\\.LZFCompressionCodec|org\\.apache\\.spark\\.io\\.SnappyCompressionCodec)","keyPatternDisplay":"spark.io.compression.codec","valuePatternDisplay":"snappy|lzf","description":"The codec used to compress internal data such as RDD partitions, broadcast variables and shuffle outputs."},{"keyPattern":"spark\\.serializer","valuePattern":"(org\\.apache\\.spark\\.serializer\\.JavaSerializer|org\\.apache\\.spark\\.serializer\\.KryoSerializer)","keyPatternDisplay":"spark.serializer","valuePatternDisplay":"org.apache.spark.serializer.JavaSerializer|org.apache.spark.serializer.KryoSerializer","description":"Class to use for serializing objects that will be sent over the network or need to be cached in serialized form."},{"keyPattern":"spark\\.rdd\\.compress","valuePattern":"(true|false)","keyPatternDisplay":"spark.rdd.compress","valuePatternDisplay":"true|false","description":"Whether to compress serialized RDD partitions (e.g. for StorageLevel.MEMORY_ONLY_SER). Can save substantial space at the cost of some extra CPU time."},{"keyPattern":"spark\\.speculation","valuePattern":"(true|false)","keyPatternDisplay":"spark.speculation","valuePatternDisplay":"true|false","description":"Whether to use speculation (recommended off for streaming)"},{"keyPattern":"spark\\.es(\\.[^\\.]+)+","valuePattern":".*","keyPatternDisplay":"spark.es.*","valuePatternDisplay":"*","description":"Configuration options for ElasticSearch"},{"keyPattern":"es(\\.([^\\.]+))+","valuePattern":".*","keyPatternDisplay":"es.*","valuePatternDisplay":"*","description":"Configuration options for ElasticSearch"},{"keyPattern":"spark\\.(storage|shuffle)\\.memoryFraction","valuePattern":"0?\\.0*([1-9])([0-9])*","keyPatternDisplay":"spark.(storage|shuffle).memoryFraction","valuePatternDisplay":"(0.0,1.0)","description":"Fraction of Java heap to use for Spark's shuffle or storage"},{"keyPattern":"spark\\.streaming\\.backpressure\\.enabled","valuePattern":"(true|false)","keyPatternDisplay":"spark.streaming.backpressure.enabled","valuePatternDisplay":"true|false","description":"Enables or disables Spark Streaming's internal backpressure mechanism (since 1.5). This enables the Spark Streaming to control the receiving rate based on the current batch scheduling delays and processing times so that the system receives only as fast as the system can process. Internally, this dynamically sets the maximum receiving rate of receivers. This rate is upper bounded by the values `spark.streaming.receiver.maxRate` and `spark.streaming.kafka.maxRatePerPartition` if they are set."},{"keyPattern":"spark\\.streaming\\.receiver\\.maxRate","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.receiver.maxRate","valuePatternDisplay":"numeric","description":"Maximum rate (number of records per second) at which each receiver will receive data. Effectively, each stream will consume at most this number of records per second. Setting this configuration to 0 or a negative number will put no limit on the rate. See the deployment guide in the Spark Streaming programing guide for mode details."},{"keyPattern":"spark\\.streaming\\.kafka\\.maxRatePerPartition","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.kafka.maxRatePerPartition","valuePatternDisplay":"numeric","description":"Maximum rate (number of records per second) at which data will be read from each Kafka partition when using the Kafka direct stream API introduced in Spark 1.3. See the Kafka Integration guide for more details."},{"keyPattern":"spark\\.streaming\\.kafka\\.maxRetries","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.kafka.maxRetries","valuePatternDisplay":"numeric","description":"Maximum number of consecutive retries the driver will make in order to find the latest offsets on the leader of each partition (a default value of 1 means that the driver will make a maximum of 2 attempts). Only applies to the Kafka direct stream API introduced in Spark 1.3."},{"keyPattern":"spark\\.streaming\\.ui\\.retainedBatches","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.ui.retainedBatches","valuePatternDisplay":"numeric","description":"How many batches the Spark Streaming UI and status APIs remember before garbage collecting."}],"enableReactNotebookComments":true,"enableAdminPasswordReset":false,"enableResetPassword":true,"maxClusterTagValueLength":255,"enableJobsSparkUpgrade":true,"enableNotebookCommandNumbers":true,"sparkVersions":[{"key":"1.6.3-db2-hadoop2-scala2.10","displayName":"Spark 1.6.3-db2 (Hadoop 2, Scala 2.10)","packageLabel":"spark-image-aba860a0ffce4f3471fb14aefdcb1d768ac66a53a5ad884c48745ef98aeb9d67","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.6.x-ubuntu15.10","displayName":"Spark 1.6.x (Hadoop 1)","packageLabel":"spark-image-8cea23fb9094e174bf5815d79009f4a8e383eb86cf2909cf6c6434ed8da2a16a","upgradable":true,"deprecated":false,"customerVisible":false},{"key":"1.4.x-ubuntu15.10","displayName":"Spark 1.4.1 (Hadoop 1)","packageLabel":"spark-image-f710650fb8aaade8e4e812368ea87c45cd8cd0b5e6894ca6c94f3354e8daa6dc","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.2.x-scala2.11","displayName":"Spark Master Branch (Experimental, Scala 2.11)","packageLabel":"spark-image-b2166ecda59b5d648306cc8a0923aa3a3bf4f25ea0d47bb42449010086f1f910","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.1.0-db2-scala2.11","displayName":"Spark 2.1.0-db2 (Scala 2.11)","packageLabel":"spark-image-267c4490a3ab8a39acdbbd9f1d36f6decdecebf013e30dd677faff50f1d9cf8b","upgradable":true,"deprecated":false,"customerVisible":false},{"key":"2.0.0-ubuntu15.10-scala2.10","displayName":"Spark 2.0.0 (Scala 2.10)","packageLabel":"spark-image-073c1b52ace74f251fae2680624a0d8d184a8b57096d1c21c5ce56c29be6a37a","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.2-db3-scala2.10","displayName":"Spark 2.0.2-db3 (Scala 2.10)","packageLabel":"spark-image-584091dedb690de20e8cf22d9e02fdcce1281edda99eedb441a418d50e28088f","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.1.0-db1-scala2.11","displayName":"Spark 2.1.0-db1 (Scala 2.11)","packageLabel":"spark-image-e8ad5b72cf0f899dcf2b4720c1f572ab0e87a311d6113b943b4e1d4a7edb77eb","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.1.1-db4-scala2.11","displayName":"Spark 2.1.1-db4 (Scala 2.11)","packageLabel":"spark-image-f6e9552fae99c2dd7d4cb60afb006f23c6a44c9a9ca6951d91b9d920f2f93e66","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.1.0-db2-scala2.10","displayName":"Spark 2.1.0-db2 (Scala 2.10)","packageLabel":"spark-image-a2ca4f6b58c95f78dca91b1340305ab3fe32673bd894da2fa8e1dc8a9f8d0478","upgradable":true,"deprecated":false,"customerVisible":false},{"key":"1.6.x-ubuntu15.10-hadoop1","displayName":"Spark 1.6.x (Hadoop 1)","packageLabel":"spark-image-8cea23fb9094e174bf5815d79009f4a8e383eb86cf2909cf6c6434ed8da2a16a","upgradable":true,"deprecated":false,"customerVisible":false},{"key":"2.0.2-db4-scala2.11","displayName":"Spark 2.0.2-db4 (Scala 2.11)","packageLabel":"spark-image-7dbc7583e8271765b8a1508cb9e832768e35489bbde2c4c790bc6766aee2fd7f","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.6.1-ubuntu15.10-hadoop1","displayName":"Spark 1.6.1 (Hadoop 1)","packageLabel":"spark-image-21d1cac181b7b8856dd1b4214a3a734f95b5289089349db9d9c926cb87d843db","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.x-gpu-scala2.11","displayName":"Spark 2.0 (Auto-updating, GPU, Scala 2.11 experimental)","packageLabel":"spark-image-968b89f1d0ec32e1ee4dacd04838cae25ef44370a441224177a37980d539d83a","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.6.2-ubuntu15.10-hadoop1","displayName":"Spark 1.6.2 (Hadoop 1)","packageLabel":"spark-image-8cea23fb9094e174bf5815d79009f4a8e383eb86cf2909cf6c6434ed8da2a16a","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"1.6.3-db1-hadoop2-scala2.10","displayName":"Spark 1.6.3-db1 (Hadoop 2, Scala 2.10)","packageLabel":"spark-image-eaa8d9b990015a14e032fb2e2e15be0b8d5af9627cd01d855df728b67969d5d9","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.6.3-db2-hadoop1-scala2.10","displayName":"Spark 1.6.3-db2 (Hadoop 1, Scala 2.10)","packageLabel":"spark-image-14112ea0645bea94333a571a150819ce85573cf5541167d905b7e6588645cf3b","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.6.2-ubuntu15.10-hadoop2","displayName":"Spark 1.6.2 (Hadoop 2)","packageLabel":"spark-image-161245e66d887cd775e23286a54bab0b146143e1289f25bd1732beac454a1561","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"1.6.1-ubuntu15.10-hadoop2","displayName":"Spark 1.6.1 (Hadoop 2)","packageLabel":"spark-image-4cafdf8bc6cba8edad12f441e3b3f0a8ea27da35c896bc8290e16b41fd15496a","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.2-db2-scala2.10","displayName":"Spark 2.0.2-db2 (Scala 2.10)","packageLabel":"spark-image-36d48f22cca7a907538e07df71847dd22aaf84a852c2eeea2dcefe24c681602f","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.x-ubuntu15.10-scala2.11","displayName":"Spark 2.0 (Ubuntu 15.10, Scala 2.11, deprecated)","packageLabel":"spark-image-8e1c50d626a52eac5a6c8129e09ae206ba9890f4523775f77af4ad6d99a64c44","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.x-scala2.10","displayName":"Spark 2.0 (Auto-updating, Scala 2.10)","packageLabel":"spark-image-859e88079f97f58d50e25163b39a1943d1eeac0b6939c5a65faba986477e311a","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.1.1-db4-scala2.10","displayName":"Spark 2.1.1-db4 (Scala 2.10)","packageLabel":"spark-image-86c0873023816ae29d99f81118dc825d6380a9968a9f7a3d0a055f5c3a8964a0","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.0.2-db1-scala2.11","displayName":"Spark 2.0.2-db1 (Scala 2.11)","packageLabel":"spark-image-c2d623f03dd44097493c01aa54a941fc31978ebe6d759b36c75b716b2ff6ab9c","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.2-db4-scala2.10","displayName":"Spark 2.0.2-db4 (Scala 2.10)","packageLabel":"spark-image-859e88079f97f58d50e25163b39a1943d1eeac0b6939c5a65faba986477e311a","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.5.x-ubuntu15.10","displayName":"Spark 1.5.2 (Hadoop 1)","packageLabel":"spark-image-c9d2a8abf41f157a4acc6d52bc721090346f6fea2de356f3a66e388f54481698","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.0.x-scala2.11","displayName":"Spark 2.0 (Auto-updating, Scala 2.11)","packageLabel":"spark-image-7dbc7583e8271765b8a1508cb9e832768e35489bbde2c4c790bc6766aee2fd7f","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.1.x-scala2.10","displayName":"Spark 2.1 (Auto-updating, Scala 2.10)","packageLabel":"spark-image-86c0873023816ae29d99f81118dc825d6380a9968a9f7a3d0a055f5c3a8964a0","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.1.0-db3-scala2.10","displayName":"Spark 2.1.0-db3 (Scala 2.10)","packageLabel":"spark-image-25a17d070af155f10c4232dcc6248e36a2eb48c24f8d4fc00f34041b86bd1626","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.0.2-db2-scala2.11","displayName":"Spark 2.0.2-db2 (Scala 2.11)","packageLabel":"spark-image-4fa852ba378e97815083b96c9cada7b962a513ec23554a5fc849f7f1dd8c065a","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"1.3.x-ubuntu15.10","displayName":"Spark 1.3.0 (Hadoop 1)","packageLabel":"spark-image-40d2842670bc3dc178b14042501847d76171437ccf70613fa397a7a24c48b912","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.0.1-db1-scala2.11","displayName":"Spark 2.0.1-db1 (Scala 2.11)","packageLabel":"spark-image-10ab19f634bbfdb860446c326a9f76dc25bfa87de6403b980566279142a289ea","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.2-db3-scala2.11","displayName":"Spark 2.0.2-db3 (Scala 2.11)","packageLabel":"spark-image-7fd7aaa89d55692e429115ae7eac3b1a1dc4de705d50510995f34306b39c2397","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.6.3-db1-hadoop1-scala2.10","displayName":"Spark 1.6.3-db1 (Hadoop 1, Scala 2.10)","packageLabel":"spark-image-d50af1032799546b8ccbeeb76889a20c819ebc2a0e68ea20920cb30d3895d3ae","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.0.2-db1-scala2.10","displayName":"Spark 2.0.2-db1 (Scala 2.10)","packageLabel":"spark-image-654bdd6e9bad70079491987d853b4b7abf3b736fff099701501acaabe0e75c41","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.x-ubuntu15.10","displayName":"Spark 2.0 (Ubuntu 15.10, Scala 2.10, deprecated)","packageLabel":"spark-image-a659f3909d51b38d297b20532fc807ecf708cfb7440ce9b090c406ab0c1e4b7e","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.0.1-db1-scala2.10","displayName":"Spark 2.0.1-db1 (Scala 2.10)","packageLabel":"spark-image-5a13c2db3091986a4e7363006cc185c5b1108c7761ef5d0218506cf2e6643840","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.1.x-scala2.11","displayName":"Spark 2.1 (Auto-updating, Scala 2.11)","packageLabel":"spark-image-f6e9552fae99c2dd7d4cb60afb006f23c6a44c9a9ca6951d91b9d920f2f93e66","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"2.1.0-db1-scala2.10","displayName":"Spark 2.1.0-db1 (Scala 2.10)","packageLabel":"spark-image-f0ab82a5deb7908e0d159e9af066ba05fb56e1edb35bdad41b7ad2fd62a9b546","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"1.6.0-ubuntu15.10","displayName":"Spark 1.6.0 (Hadoop 1)","packageLabel":"spark-image-10ef758029b8c7e19cd7f4fb52fff9180d75db92ca071bd94c47f3c1171a7cb5","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"1.6.x-ubuntu15.10-hadoop2","displayName":"Spark 1.6.x (Hadoop 2)","packageLabel":"spark-image-161245e66d887cd775e23286a54bab0b146143e1289f25bd1732beac454a1561","upgradable":true,"deprecated":false,"customerVisible":false},{"key":"2.0.0-ubuntu15.10-scala2.11","displayName":"Spark 2.0.0 (Scala 2.11)","packageLabel":"spark-image-b4ec141e751f201399f8358a82efee202560f7ed05e1a04a2ae8778f6324b909","upgradable":true,"deprecated":true,"customerVisible":false},{"key":"2.1.0-db3-scala2.11","displayName":"Spark 2.1.0-db3 (Scala 2.11)","packageLabel":"spark-image-ccbc6b73f158e2001fc1fb8c827bfdde425d8bd6d65cb7b3269784c28bb72c16","upgradable":true,"deprecated":false,"customerVisible":true}],"enableRestrictedClusterCreation":true,"enableFeedback":true,"enableClusterAutoScaling":false,"enableUserVisibleDefaultTags":true,"defaultNumWorkers":0,"serverContinuationTimeoutMillis":10000,"autoTerminateClustersByDefault":false,"driverStderrFilePrefix":"stderr","enableNotebookRefresh":false,"accountsOwnerUrl":"https://accounts.cloud.databricks.com/registration.html#login","driverStdoutFilePrefix":"stdout","defaultNodeTypeToPricingUnitsMap":{"r3.2xlarge":2,"class-node":1,"m4.2xlarge":0.5,"r4.xlarge":1,"m4.4xlarge":0.5,"r4.16xlarge":8,"p2.8xlarge":16,"m4.10xlarge":0.5,"r3.8xlarge":8,"r4.4xlarge":4,"dev-tier-node":1,"c3.8xlarge":4,"r3.4xlarge":4,"i2.4xlarge":6,"m4.xlarge":0.5,"r4.8xlarge":8,"r4.large":0.5,"development-node":1,"i2.2xlarge":3,"g2.8xlarge":6,"memory-optimized":1,"m4.large":0.5,"p2.16xlarge":24,"c3.2xlarge":1,"c4.2xlarge":1,"i2.xlarge":1.5,"compute-optimized":1,"c4.4xlarge":2,"c3.4xlarge":2,"g2.2xlarge":1.5,"p2.xlarge":2,"m4.16xlarge":0.5,"c4.8xlarge":4,"r3.xlarge":1,"r4.2xlarge":2,"i2.8xlarge":12},"enableSparkDocsSearch":true,"sparkHistoryServerEnabled":true,"enableEBSVolumesUI":false,"sanitizeMarkdownHtml":true,"enableIPythonImportExport":true,"enableClusterTagsUIForJobs":true,"enableClusterTagsUI":false,"enableNotebookHistoryDiffing":true,"branch":"2.44","accountsLimit":3,"enableSparkEnvironmentVariables":true,"enableX509Authentication":false,"enableStructuredStreamingNbOptimizations":false,"enableNotebookGitBranching":true,"local":false,"enableClusterAutoScalingForJobs":false,"enableStrongPassword":false,"displayDefaultContainerMemoryGB":6,"enableNotebookCommandMode":true,"disableS3TableImport":false,"deploymentMode":"production","useSpotForWorkers":true,"enableUserInviteWorkflow":true,"enableStaticNotebooks":true,"perClusterAutoTerminationEnabled":false,"enableCssTransitions":true,"defaultAutoTerminationInactivityMin":180,"minClusterTagKeyLength":1,"showHomepageFeaturedLinks":true,"pricingURL":"https://databricks.com/product/pricing","enableClusterAclsConfig":false,"useTempS3UrlForTableUpload":false,"notifyLastLogin":false,"enableSshKeyUIByTier":false,"defaultAutomatedPricePerDBU":0.2,"enableNotebookGitVersioning":true,"files":"files/","feedbackEmail":"[email protected]","enableDriverLogsUI":true,"enableWorkspaceAclsConfig":false,"dropzoneMaxFileSize":2047,"enableNewClustersList":false,"enableNewDashboardViews":true,"driverLog4jFilePrefix":"log4j","enableSingleSignOn":true,"enableMavenLibraries":true,"displayRowLimit":1000,"deltaProcessingAsyncEnabled":true,"enableSparkEnvironmentVariablesUI":false,"defaultSparkVersion":{"key":"2.1.x-scala2.10","displayName":"Spark 2.1 (Auto-updating, Scala 2.10)","packageLabel":"spark-image-86c0873023816ae29d99f81118dc825d6380a9968a9f7a3d0a055f5c3a8964a0","upgradable":true,"deprecated":false,"customerVisible":true},"enableCustomSpotPricing":false,"enableMountAclsConfig":false,"useDevTierHomePage":true,"enableClusterClone":true,"enableNotebookLineNumbers":true,"enablePublishHub":false,"minAutoTerminationInactivityMin":10,"notebookHubUrl":"http://hub.dev.databricks.com/","showSqlEndpoints":false,"enableClusterAclsByTier":false,"databricksDocsBaseUrl":"https://docs.databricks.com/","cloud":"AWS","disallowAddingAdmins":true,"enableSparkConfUI":true,"featureTier":"DEVELOPER_BASIC_TIER","mavenCentralSearchEndpoint":"http://search.maven.org/solrsearch/select","enableOrgSwitcherUI":true,"clustersLimit":1,"enableJdbcImport":true,"logfiles":"logfiles/","enableWebappSharding":true,"enableClusterDeltaUpdates":true,"enableSingleSignOnLogin":false,"ebsVolumeSizeLimitGB":{"GENERAL_PURPOSE_SSD":[100,4096],"THROUGHPUT_OPTIMIZED_HDD":[500,4096]},"enableMountAcls":false,"requireEmailUserName":true,"dbcFeedbackURL":"mailto:[email protected]","enableMountAclService":true,"enableWorkspaceAcls":false,"maxClusterTagKeyLength":127,"gitHash":"16bec05fa08fe1dd3350ef898eaf4457d7c34e6a","showWorkspaceFeaturedLinks":true,"signupUrl":"https://databricks.com/try-databricks","allowFeedbackForumAccess":true,"enableImportFromUrl":true,"enableMiniClusters":true,"enableNewTableUI":true,"enableDebugUI":false,"enableStreamingMetricsDashboard":true,"allowNonAdminUsers":true,"enableSingleSignOnByTier":false,"enableJobsRetryOnTimeout":true,"useStandardTierUpgradeTooltips":true,"staticNotebookResourceUrl":"https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/","enableSpotClusterType":true,"enableSparkPackages":true,"dynamicSparkVersions":true,"enableClusterTagsUIByTier":false,"enableNotebookHistoryUI":true,"enableClusterLoggingUI":true,"maxAutoTerminationInactivityMin":10000,"enableDatabaseDropdownInTableUI":false,"showDebugCounters":false,"enableInstanceProfilesUI":false,"enableFolderHtmlExport":true,"homepageFeaturedLinks":[{"linkURI":"https://docs.databricks.com/_static/notebooks/gentle-introduction-to-apache-spark.html","displayName":"Introduction to Apache Spark on Databricks","icon":"img/home/Python_icon.svg"},{"linkURI":"https://docs.databricks.com/_static/notebooks/databricks-for-data-scientists.html","displayName":"Databricks for Data Scientists","icon":"img/home/Scala_icon.svg"},{"linkURI":"https://docs.databricks.com/_static/notebooks/structured-streaming-python.html","displayName":"Introduction to Structured Streaming","icon":"img/home/Python_icon.svg"}],"enableClusterStart":true,"enableEBSVolumesUIByTier":false,"upgradeURL":"https://accounts.cloud.databricks.com/registration.html#login","notebookLoadingBackground":"#fff","sshContainerForwardedPort":2200,"enableServerAutoComplete":true,"enableStaticHtmlImport":true,"enableInstanceProfilesByTier":false,"defaultMemoryPerContainerMB":6000,"enablePresenceUI":true,"accounts":true,"useOnDemandClustersByDefault":true,"useFramedStaticNotebooks":false,"enableNewProgressReportUI":true,"defaultCoresPerContainer":4,"showTerminationReason":true,"enableNewClustersGet":true,"showPricePerDBU":false,"showSqlProxyUI":true};</script>
<script>var __DATABRICKS_NOTEBOOK_MODEL = {"version":"NotebookV1","origId":3162710545890990,"name":"Introduction to Scala Programming","language":"scala","commands":[{"version":"CommandV1","origId":3162710545890993,"guid":"2427f9db-c7b9-40de-80d2-259654027086","subtype":"command","commandType":"auto","position":0.5,"command":"%md\n\n# Introduction To Scala Programming\n[Sina Sheikholeslami](https://www.linkedin.com/in/sinasheikholeslami/), [Big Data R&D Engineer @ Digikala.com](mailto:[email protected])</br>\n[Mohammad Mazrae](https://www.linkedin.com/in/mohammadmazraeh/), [Big Data Engineer & Data Scientist @ Digikala.com](mailto:[email protected])</br>\n(Last Updated: May 1 2017)\n\n\nWelcome to Scala, and let's get started!</br>\nWe'll demonstrate the fundamental concepts and the essential syntax of Scala in this notebook.</br>","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184824616,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"e3dc24af-11c6-4606-8879-7a219274ab28"},{"version":"CommandV1","origId":755287174841047,"guid":"c40a051f-09ef-4a28-9b14-dd99d0c22e16","subtype":"command","commandType":"auto","position":0.75,"command":"%md\n\n## But First... Let's Say Hello!\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184824669,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"bc532cf0-7c96-4581-b1c9-73c023e70a7d"},{"version":"CommandV1","origId":755287174841048,"guid":"12a865d8-32df-487c-8e21-4b197a5d9109","subtype":"command","commandType":"auto","position":0.875,"command":"println(\"Hello World!\")","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Hello World!\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492253884143,"submitTime":1492253880511,"finishTime":1492253891530,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"b09b1a4e-6d33-4db6-86f6-ebeb897a344a"},{"version":"CommandV1","origId":755287174841050,"guid":"368a7917-9462-4282-80bc-c8a44d0cec80","subtype":"command","commandType":"auto","position":1.40625,"command":"%md\nOh, the traditions! 😁","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184824800,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"bc17753f-a312-44e5-93a0-aa4aa5bb0a65"},{"version":"CommandV1","origId":755287174841049,"guid":"bb5dacdb-00d2-4c7f-bb4b-21d67bb836a8","subtype":"command","commandType":"auto","position":1.9375,"command":"%md\n##Interactive Scala: The REPL\n- One of the advantages of Scala is its **Read, Eval, Print Loop (REPL)** that let's you play with the language in an interactive manner.</br>\n- The de facto build tool for Scala is called **SBT (Simple Build Tool)** that provides its own REPL and has lots of functionalities. While in SBT, you can start its REPL with `console` command.</br>\n- You can also use the **Worksheet** feature of IDE's like Intellij IDEA and Eclipse. NetBeans offers the same functionality by the name of *Interactive Console*. </br>\n- **Notebooks** let you play with Scala in a similiar fashion to a REPL. For this tutorial, we will be using a **Databricks Notebook** that has a free, community edition suitable for learning Scala and Spark (and it's sanction-free!).\n\nRemember, using the REPL is a very fun, easy, and effective way to get yourself familiar with Scala features and syntax.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184824840,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"8507ffaa-d394-4582-a8bf-e6864e68c25f"},{"version":"CommandV1","origId":755287174841051,"guid":"63275ef3-3b9c-4294-bcef-a267dca5fbf7","subtype":"command","commandType":"auto","position":2.9375,"command":"%md\n# Scala Basics\nOkay. Let's explore the basic syntax.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184824896,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"fa581d33-8050-4b2b-adb4-3ef52ce8ce21"},{"version":"CommandV1","origId":755287174841052,"guid":"a8d9c2fc-e666-4151-b213-8c2162cc034e","subtype":"command","commandType":"auto","position":3.9375,"command":"%md \n## Defining Variables\n- Use `val` keyword to define *immutable* variables. We can't change what a val points to, but if the object itself is mutable, we can change it.\n- Use `var` keyword to define *mutable* variables.\n\n\nVariables defined using `val` and `var` must be initialized immediately.</br>\n**Functional Programming** encourages us to use **immutable** variables whenever possible. Mutable variables are common sources of bugs, and actually you can't use them that much in distributed programs, such as the ones we run using Spark.</br>\nLet's define a variable called `workshopTitle` and assign it a `String`, `\"Introduction to Scala Programming\"`:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184824947,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"598013df-f3a8-4f0f-a213-c00122905762"},{"version":"CommandV1","origId":755287174841053,"guid":"18171787-1498-48b0-b4f6-73df895882ef","subtype":"command","commandType":"auto","position":4.9375,"command":"val workshopTitle = \"Introduction to Scala Programming\"","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">workshopTitle: String = Introduction to Scala Programming\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492254311170,"submitTime":1492254311162,"finishTime":1492254311355,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"530945dc-8c36-4ece-84e3-1606281eedb5"},{"version":"CommandV1","origId":755287174841054,"guid":"9455dcfb-4713-4ee3-aa2f-2c46b2eae197","subtype":"command","commandType":"auto","position":5.9375,"command":"%md\nLet's print its value:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825061,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"d8ea3e94-e06f-4ad4-bd7f-a2e9551c6700"},{"version":"CommandV1","origId":755287174841055,"guid":"477978ac-bd4e-4c33-9d45-b30ac74cf3f8","subtype":"command","commandType":"auto","position":6.9375,"command":"println(workshopTitle)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Introduction to Scala Programming\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492254383074,"submitTime":1492254383064,"finishTime":1492254383262,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"c78af974-040e-4bf0-9f0c-521a4fc771dd"},{"version":"CommandV1","origId":755287174841056,"guid":"e553598d-2b68-4493-b675-2923bf35a144","subtype":"command","commandType":"auto","position":7.9375,"command":"%md\nSuppose its tomorrow and we're at \"Stream Processing and Machine Learning with Spark\" workshop, so we should change the value of `workshopTitle`. Let's do that.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825177,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"f6114f95-bdc7-4e76-b021-4c8cd03f9126"},{"version":"CommandV1","origId":755287174841057,"guid":"727321c3-92ab-46a0-87e0-90b767c71e1b","subtype":"command","commandType":"auto","position":8.9375,"command":"workshopTitle = \"Stream Processing and Machine Learning with Spark\"","commandVersion":0,"state":"error","results":null,"errorSummary":"<div class=\"ansiout\"><console>:34: error: reassignment to val\n workshopTitle = "Stream Processing and Machine Learning with Spark"\n ^\n</div>","error":null,"workflows":[],"startTime":1492254487833,"submitTime":1492254487833,"finishTime":1492254487943,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"2b5f6d88-8f58-4247-9f62-dbbfa2743306"},{"version":"CommandV1","origId":755287174841058,"guid":"abbe4198-f25d-410f-81f9-d7efa631e75b","subtype":"command","commandType":"auto","position":9.9375,"command":"%md\n###Oops!\nRemember, immutable means \"unchanging over time\", so you simply can't reassign or change the value of an immutable variable.</br>\nThis was probably your first Scala compile error, but the good news is, it was on purpose! 😉","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825288,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"c51262ba-8dcc-4c71-80e8-21cb2136bf05"},{"version":"CommandV1","origId":755287174841070,"guid":"69c324cb-e073-49f2-b531-d23e4c85375b","subtype":"command","commandType":"auto","position":10.4375,"command":"%md\n### Type Inference\n\nAs you may have noticed, we didn't explicitly defined the type of `workshopTitle`. Type information is often inferred in Scala. This let's us write codes faster, but caution should be taken when you are not sure about the type Scala is going to infer about your variable.</br>We could have explicitly defined `workshopTitle` as a `String`:</br>\n`val workshopTitle: String = \"Introduction to Scala Programming\"`","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825337,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"2692fc89-fbca-4c25-9006-ac299ea79df5"},{"version":"CommandV1","origId":755287174841071,"guid":"e45d3331-7147-48a6-b663-ce1b7bb70bb5","subtype":"command","commandType":"auto","position":10.6875,"command":"%md\n## Semicolons and Comments\nYou don't need to place a semicolon at the end of the lines.</br>\nScala follows the same commenting conventions of Java.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825387,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"d62ba5ba-74c1-4fe1-95a1-6aadb6dbebc2"},{"version":"CommandV1","origId":755287174841061,"guid":"f39dfd74-043d-4094-97e0-e84875f0aab4","subtype":"command","commandType":"auto","position":12.9375,"command":"%md\n## If clause\nScala `if` clauses are like Java's. The difference, however, is that every `if` statement is actually an expression that returns value, so we can assign the result to a variable.</br>\nConsider this example:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825500,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"a953328b-c3f3-4627-8b52-1c999b25e1df"},{"version":"CommandV1","origId":99369287466342,"guid":"d1bb5354-584b-4f14-a83e-9b7b829a16a4","subtype":"command","commandType":"auto","position":13.4375,"command":"val configFile = new java.io.File(\"SomeFile.txt\")\n\nval configPath = if(configFile.exists()){\n configFile.getAbsolutePath()\n} else{\n configFile.createNewFile()\n configFile.getAbsolutePath()\n}","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">configFile: java.io.File = SomeFile.txt\nconfigPath: String = /databricks/driver/SomeFile.txt\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492254931203,"submitTime":1492254931193,"finishTime":1492254931411,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"3effd68b-72ce-4efd-afb9-7da35f7d914a"},{"version":"CommandV1","origId":755287174841062,"guid":"1d8c8ac2-3ac3-459b-95f3-1370beb29daa","subtype":"command","commandType":"auto","position":13.9375,"command":"%md\n## For-Comprehensions\n\nIn Scala, `for` control structure is very feature rich. Let's explore it through a number of examples.</br>\nWe'll start by a basic `for` expression:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825559,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"c0bdc287-7237-457c-9232-102f804310f8"},{"version":"CommandV1","origId":99369287466330,"guid":"17eb1796-2a32-458b-bb66-bb239da65529","subtype":"command","commandType":"auto","position":14.4375,"command":"val weekDays = List(\"Saturday\", \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\")\nfor(day <- weekDays)\n println(day)\n","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Saturday\nSunday\nMonday\nTuesday\nWednesday\nThursday\nFriday\nweekDays: List[String] = List(Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492255156282,"submitTime":1492255156273,"finishTime":1492255157246,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"b72105b9-6691-495f-8331-1d0a39f52f67"},{"version":"CommandV1","origId":99369287466331,"guid":"74751ec5-b4f5-4ae4-951d-15fcc3296306","subtype":"command","commandType":"auto","position":14.6875,"command":"%md\nSo we iterated through the list of weekdays and for each element (each weekday), we created a temporary variable called `day` with the value of the element, and printed it.</br>\nThe `day <- weekDays` expression is called a *generator expression*. The `<-` (left arrow) operator is used to iterate through collections.</br>\nWe can also leverage `Range` to quickly write a `for` loop:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"948ec3ee-d69c-45ad-932d-d56ae85dbd83"},{"version":"CommandV1","origId":99369287466332,"guid":"3272500a-28e2-45b0-9160-48cb6d2cc35f","subtype":"command","commandType":"auto","position":14.8125,"command":"for (i <- 1 to 10) println(i)","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492239650256,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"464d1a57-4934-47f1-b3a0-c99f1bd89c53"},{"version":"CommandV1","origId":99369287466333,"guid":"f71143a2-1323-4b4f-a653-38bdd0129e8c","subtype":"command","commandType":"auto","position":14.875,"command":"%md\n### Guards\nWe can add `if` expressions to filter for the elements we want to keep. These expressions are called *guards*.</br>\nLet's filter for just the days that start with \"S\", and notice the difference in syntax:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"d6fa36aa-2e4b-45d3-aac9-881923672a02"},{"version":"CommandV1","origId":99369287466334,"guid":"193b5215-3043-45c9-b979-5a89874d13dd","subtype":"command","commandType":"auto","position":14.90625,"command":"for(day <- weekDays\n if day.startsWith(\"S\"))\nprintln(day)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Saturday\nSunday\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492255349025,"submitTime":1492255349015,"finishTime":1492255349419,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"a1ff065f-e3aa-4646-97cb-017ad7ba02bb"},{"version":"CommandV1","origId":99369287466335,"guid":"595264e4-a8bb-4e4c-b61f-28de8b87b0d9","subtype":"command","commandType":"auto","position":14.921875,"command":"%md\nJust so you know, the above `for` loop can be re-written using curly braces:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"5af2421c-c1e6-4114-ae52-b052d0efabe7"},{"version":"CommandV1","origId":99369287466336,"guid":"d5d98e09-b0b8-40cb-ade0-70ac41724f50","subtype":"command","commandType":"auto","position":14.9296875,"command":"for{ day <- weekDays\n if day.startsWith(\"S\")\n}{\n println(day)\n}","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Saturday\nSunday\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492255399097,"submitTime":1492255399087,"finishTime":1492255399379,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"b7b87d9b-a7e8-4cc9-8e8c-4ba1b00a41ef"},{"version":"CommandV1","origId":99369287466337,"guid":"8c069d1a-4651-42b3-baa1-6a8c2e436261","subtype":"command","commandType":"auto","position":14.93359375,"command":"%md\nRemember that it's gonna take a while to get familiar with all the different forms of writing expressions.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"eef691d9-375f-4e2c-8729-39c135aa264e"},{"version":"CommandV1","origId":99369287466339,"guid":"cdb57aca-af43-4b05-9412-b41e9681f878","subtype":"command","commandType":"auto","position":14.935546875,"command":"%md\n### Yielding\nThe `yield` keyword is used to generate new collections with `for` expressions:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"bf54ab7a-c95a-4dd7-b359-7ddb199295f8"},{"version":"CommandV1","origId":99369287466340,"guid":"38d05295-d577-45b4-8d88-c6a11ecb14b9","subtype":"command","commandType":"auto","position":14.9365234375,"command":"val filteredDays = for{\n day <- weekDays\n if day.startsWith(\"S\")\n}yield day\n\nfilteredDays.foreach(println)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Saturday\nSunday\nfilteredDays: List[String] = List(Saturday, Sunday)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492255513567,"submitTime":1492255513558,"finishTime":1492255514183,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"34c35221-bcc4-4307-b4f8-b2e76e7369b5"},{"version":"CommandV1","origId":99369287466341,"guid":"6b17f777-8ca3-4990-8610-639f8c62a30c","subtype":"command","commandType":"auto","position":14.93701171875,"command":"%md\nNote that if you do not specify the type of the yielded collection, it is inferred from the type of the original collection being iterated over.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"d6d26a64-facb-44a7-9b46-108cfb06c6d8"},{"version":"CommandV1","origId":755287174841064,"guid":"14a28161-7e34-4f8c-93d2-2faeb813a941","subtype":"command","commandType":"auto","position":15.9375,"command":"%md\n## Method Definition\n\nMethod definitions begin with the `def` keyword, followed by an optional list of arguments. After that, you can place an optional return type. If you don't provide the return type, it will be inferred. After that, a `=` acts as the separator between method signature and method body.</br>\nLet's define a method that takes a *variable-length* list of strings and returns the upper-cased version of the input list:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825671,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"5b4d5842-ec5f-4dc6-8e67-004ceb82b50d"},{"version":"CommandV1","origId":755287174841101,"guid":"a614e2da-6d51-4f8e-9140-612bce356b9c","subtype":"command","commandType":"auto","position":16.4375,"command":"def upper(strings: String*): Seq[String] = {\n strings.map((s: String) => s.toUpperCase())\n}","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">upper: (strings: String*)Seq[String]\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492257738841,"submitTime":1492257738831,"finishTime":1492257739178,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"58200b0e-fba3-4ea8-a2cf-871490f2ada0"},{"version":"CommandV1","origId":755287174841102,"guid":"7286deb8-a39d-40aa-9534-cd0157814667","subtype":"command","commandType":"auto","position":16.6875,"command":"upper(\"First String\", \"Second String\").foreach(println)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">FIRST STRING\nSECOND STRING\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492257759745,"submitTime":1492257759737,"finishTime":1492257759951,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"30ba9d29-6473-4d5e-98e3-a4bfb715d819"},{"version":"CommandV1","origId":755287174841106,"guid":"f6fd888f-d696-497c-8272-ca755ce1beb2","subtype":"command","commandType":"auto","position":16.75,"command":"%md\nIn Scala, the last *expression* in a function or method is the return value.</br> However, Scala contains `return` keyword for interoperability with Java, but it is rarely used in methods.</br>\nIf a method takes no parameters, you can define it without parantheses. However, the convention is to omit parantheses for no-argument methods that have no side effects (for example, a method that returns the size of a collection) and add empty parantheses if side effects (e.g. I/O) are performed, as a caution to the user.</br>\n#### A Note on Method Return Type Inferrence\nAlthough you can leave out the return type specification, the best practice is to always define the return type explicitly. Explicit return types express what you expect the method to return. This is specially important when writing public APIs.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825871,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"56863830-cdca-4949-9bf7-208889fb6b12"},{"version":"CommandV1","origId":755287174841105,"guid":"bc382bc8-f5ee-4b1f-9bfd-79f3ec701987","subtype":"command","commandType":"auto","position":16.8125,"command":"%md\n## Anonymous Functions\n\nWe could achieve the same functionality of the `upper` method with just defined, without explicitly defining a method, and using what is called an *anonymous function*:\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825921,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"19c794d9-fb27-4cf7-b0d1-a92fd3d2c6a3"},{"version":"CommandV1","origId":755287174841107,"guid":"5f9e5a75-0434-4f28-a05b-4df18b657313","subtype":"command","commandType":"auto","position":16.875,"command":"val listOfStrings: List[String] = List(\"First\", \"Second\", \"Third\", \"Fourth\") // we could also just write: val listOfStrings = List(\"First\",\"Second,\"Third\",\"Fourth\")\n\nlistOfStrings.map(s => s.toUpperCase()).foreach(println)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">FIRST\nSECOND\nTHIRD\nFOURTH\nlistOfStrings: List[String] = List(First, Second, Third, Fourth)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258045127,"submitTime":1492258045119,"finishTime":1492258045473,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"3d6d8461-bd2f-4d33-b427-7993e7b378cf"},{"version":"CommandV1","origId":755287174841108,"guid":"868d9fa3-1210-497a-8f6e-8937b0510dc8","subtype":"command","commandType":"auto","position":16.90625,"command":"listOfStrings.map(_.toUpperCase)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res8: List[String] = List(FIRST, SECOND, THIRD, FOURTH)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258126332,"submitTime":1492258126325,"finishTime":1492258126643,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"49f48b6f-1b73-41b5-aae4-8dd6d2bf8056"},{"version":"CommandV1","origId":755287174841114,"guid":"19aad675-cd67-4444-990d-f12f71e79181","subtype":"command","commandType":"auto","position":16.921875,"command":"%md\n## Higher-Order Functions\n\nWhen a function accepts other functions as arguments or returns functions as values, it is called a *higher-order function* (HOF).","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"6e9ee763-4aad-47a7-9b92-1b3a35617965"},{"version":"CommandV1","origId":755287174841066,"guid":"d0766341-4f9d-4c67-b069-109d09673189","subtype":"command","commandType":"auto","position":17.9375,"command":"%md\n## Tuples\nEver wanted to return more than one value from a method? Scala provides a concise and powerful data structure for this purpose, called **TupleN** (*N* can be between 1 and 22).","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184826184,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"b33e4e62-b769-47c3-8d66-5211272954c6"},{"version":"CommandV1","origId":3627984262107850,"guid":"8a51e087-6b49-425c-a8fa-089fdede5ddb","subtype":"command","commandType":"auto","position":18.4375,"command":"val t2: Tuple2[String, String] = (\"One\", \"Two\") \n\nprintln(\"First is: \" + t2._1)\nprintln(\"Second is: \" + t2._2)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">First is: One\nSecond is: Two\nt2: (String, String) = (One,Two)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258316941,"submitTime":1492258316934,"finishTime":1492258317301,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"f9ce9ce6-ed07-4f97-ba7e-c343bd5bc732"},{"version":"CommandV1","origId":3627984262107853,"guid":"b45f6dee-4d19-43f3-8243-aa5143153b76","subtype":"command","commandType":"auto","position":18.6875,"command":"val t3 = (\"This\", \"is\", \"third\")\nprintln(t3)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">(This,is,third)\nt3: (String, String, String) = (This,is,third)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258354481,"submitTime":1492258354473,"finishTime":1492258354632,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"b41f4876-269b-4d56-8f0a-692a093a3b7d"},{"version":"CommandV1","origId":3627984262107854,"guid":"27e887f1-c2b4-4012-a6bd-1b34df53e042","subtype":"command","commandType":"auto","position":18.8125,"command":"val t4 = Tuple4(\"This\", \"is\", \"Tuple\", 4)\nprintln(t4)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">(This,is,Tuple,4)\nt4: (String, String, String, Int) = (This,is,Tuple,4)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258373613,"submitTime":1492258373597,"finishTime":1492258373816,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"cd1184a5-28aa-49d9-9d69-8580c5e36171"},{"version":"CommandV1","origId":755287174841067,"guid":"cc858398-b7e2-41e3-9afb-236073dc2da5","subtype":"command","commandType":"auto","position":18.9375,"command":"%md\n## Classes\nIn Scala, a class definition begins with the `class` keyword and the body is placed inside the outermost curly braces `{}`.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184826254,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"822f2e92-291c-4247-91ee-8c3513569222"},{"version":"CommandV1","origId":755287174841112,"guid":"f5b88276-e6f5-4655-878a-9d7e2cac0b2f","subtype":"command","commandType":"auto","position":19.1875,"command":"class Upper{\n def upper(strings: String*): Seq[String] = {\n strings.map((s: String) => s.toUpperCase())\n }\n}\nval up = new Upper\nprintln(up.upper(\"Scala\", \"is\", \"cool!\")) // print the actual list","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">ArrayBuffer(SCALA, IS, COOL!)\ndefined class Upper\nup: Upper = Upper@20b44e42\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258630182,"submitTime":1492258630174,"finishTime":1492258630479,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"bed7153b-cc62-4081-86a5-5d3516e8d650"},{"version":"CommandV1","origId":3627984262107860,"guid":"97a3fc5d-7043-4251-ba7b-7cd6d6f0f058","subtype":"command","commandType":"auto","position":19.3125,"command":"%md\nLet's define a class named `Person` with two fields: `name` and `age`:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"43b87898-0cd8-4cce-87a4-d8735b0b24f8"},{"version":"CommandV1","origId":3627984262107861,"guid":"d0c9222c-ed75-451c-a314-530c1c300e77","subtype":"command","commandType":"auto","position":19.375,"command":"class Person(val name: String, var age: Int = 12)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">defined class Person\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258749078,"submitTime":1492258749071,"finishTime":1492258749279,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"44f266ce-0f40-491b-a3f2-9e7c4da850d5"},{"version":"CommandV1","origId":3627984262107862,"guid":"843c160e-fa4c-402f-8e09-ce0d211bda01","subtype":"command","commandType":"auto","position":19.40625,"command":"val p = new Person(\"Sina\", 24)\n\nprintln(p.name)\nprintln(p.age)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Sina\n24\np: Person = Person@256ab6d7\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258780762,"submitTime":1492258780755,"finishTime":1492258780937,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"14879ddc-8a96-4ea5-b7af-2d6756050377"},{"version":"CommandV1","origId":3627984262107863,"guid":"33180a6e-ba38-4f40-b3db-2f5c4f6c1754","subtype":"command","commandType":"auto","position":19.421875,"command":"%md\nLet's change the `age`:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"83244e0c-4824-46da-8f35-9de3430cbdf3"},{"version":"CommandV1","origId":3627984262107864,"guid":"879c5d91-a26e-4b24-9981-6f83a205a909","subtype":"command","commandType":"auto","position":19.4296875,"command":"p.age = 25\nprintln(p.age)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">25\np.age: Int = 25\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258803036,"submitTime":1492258803029,"finishTime":1492258803211,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"cc1917da-2009-4de5-96ca-78af16789ecd"},{"version":"CommandV1","origId":755287174841109,"guid":"d3539ef0-76e6-4a69-9e80-a92934227825","subtype":"command","commandType":"auto","position":19.4375,"command":"%md\n### Objects\nTake a look at this block of code:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184826382,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"f6457f34-5875-403a-bd10-f03129046dc1"},{"version":"CommandV1","origId":755287174841111,"guid":"15e4d881-a543-42cb-809f-d93b042d2c9e","subtype":"command","commandType":"auto","position":19.5625,"command":"object UpperObject{\n def upper(strings: String*) = strings.map(_.toUpperCase())\n}\nprintln(UpperObject.upper(\"Scala\", \"is\", \"cool!\"))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">ArrayBuffer(SCALA, IS, COOL!)\ndefined object UpperObject\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492258909523,"submitTime":1492258909516,"finishTime":1492258909812,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"804e8f0b-ad52-4bd5-98a1-e265e0256ddf"},{"version":"CommandV1","origId":755287174841110,"guid":"7d280db2-a67c-42c1-9fdb-67287e394a6b","subtype":"command","commandType":"auto","position":19.6875,"command":"%md\nWhen we declare something with the `object` keyword, it will be considered a *singleton* (Remember the Singleton Design Pattern?). We are declaring a class, but the Scala runtime will only create one instance of it, thus we cannot write `new Upper`.</br>\nAlso, in Scala, the `main` method must be placed inside an `object`. (In Java, `main` must be a `static` method in a `class`.)","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"c1d7adca-c5d6-4140-9070-08d6575b5241"},{"version":"CommandV1","origId":755287174841068,"guid":"499371f7-23b6-4ae6-8109-dd4c8025040c","subtype":"command","commandType":"auto","position":19.9375,"command":"%md\n## Pattern Matching\n\nPattern matching is a powerful feature of Scala, and can be used for decomposing data structures. It can also be used for exception handling.</br>","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"08604d46-5342-46d7-b96a-1f51af827c3a"},{"version":"CommandV1","origId":99369287466324,"guid":"e044cf66-a411-4e2d-9a05-d9615f9e8136","subtype":"command","commandType":"auto","position":20.1875,"command":"val bools = Seq(true, false)\n\nfor(bool <- bools){\n bool match{\n case true => println(\"It's true\")\n case false => println(\"It's false\")\n }\n}","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">It's true\nIt's false\nbools: Seq[Boolean] = List(true, false)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492259048255,"submitTime":1492259048248,"finishTime":1492259048555,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"e4faf60e-683b-40fd-bef3-981ffe251776"},{"version":"CommandV1","origId":99369287466338,"guid":"7bffc97a-4b6a-4d20-96a9-52ec08b16772","subtype":"command","commandType":"auto","position":20.25,"command":"%md\nAnother, more sophisticated example:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"451acbe8-3cee-479b-9c3f-d32bf4f8a923"},{"version":"CommandV1","origId":99369287466327,"guid":"c58c8ec0-5c9e-484b-899f-ecc94f3a6d6f","subtype":"command","commandType":"auto","position":20.3125,"command":"val sequence = Seq(1, 2, 2.7, \"one\", \"two\", 'four)\nfor(x <- sequence)\n{ val str = x match {\n case 1 => \"int 1\"\n case i: Int => \"other int: \"+i\n case d: Double => \"a double: \"+d\n case \"one\" => \"string one\"\n case s: String => \"other string: \"+s\n case unexpected => \"unexpected value: \"+unexpected\n }\n println(str)\n }","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">int 1\nother int: 2\na double: 2.7\nstring one\nother string: two\nunexpected value: 'four\nsequence: Seq[Any] = List(1, 2, 2.7, one, two, 'four)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492259765267,"submitTime":1492259765260,"finishTime":1492259765588,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"7234f434-2ea5-44a0-83a6-696589befedc"},{"version":"CommandV1","origId":755287174841116,"guid":"e08ff3b2-3999-4400-a584-b8dada87b4d3","subtype":"command","commandType":"auto","position":20.4375,"command":"%md\n## Partial Functions\nA Partial Function consists only of `case` clauses, and the entire body must be enclosed in braces.</br>When one of the patterns matches, the expressions after the `=>` up to the next `case` keyword (or, the end of function) are evaluated.</br>\nIf the function is called with an input that doesn't match one of the `case` clauses, a `MathError` will be thrown at the runtime.</br>\nYou can test if a partial function matches its input using `isDefinedAt` method.</br>\nA classic example of a partial function in mathematics is division (x/y) which is undefined when *y* is 0.</br>","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"e2df0319-9634-49e5-9db0-9b54fda63f61"},{"version":"CommandV1","origId":3627984262107870,"guid":"e32b9d62-80b1-48ba-88d3-dac25ecc8027","subtype":"command","commandType":"auto","position":20.6875,"command":"val one: PartialFunction[Int, String] = { case 1 => \"one\"}\nprintln(one.isDefinedAt(1))\nprintln(one.isDefinedAt(0))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">true\nfalse\none: PartialFunction[Int,String] = <function1>\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492259847354,"submitTime":1492259847348,"finishTime":1492259847614,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"c1407cb8-63e4-42f4-9de1-fd05b7d1ab5e"},{"version":"CommandV1","origId":3627984262107872,"guid":"e68ad8f3-32d6-460b-91ed-1fb8c91d3c2f","subtype":"command","commandType":"auto","position":20.75,"command":"val two: PartialFunction[Any, String] = {\n case 2 => \"literal for two\"\n case s: String if (s.length < 5) => \"Length is less than 5\"\n case s: String => \"You entered a string\"\n case d: Double => \"It's a Double\"\n case unexpected => \"Unexpected input\"\n}","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">two: PartialFunction[Any,String] = <function1>\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492259865713,"submitTime":1492259865706,"finishTime":1492259865950,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"fcec2c93-965d-4a8f-bc51-78372589949a"},{"version":"CommandV1","origId":3627984262107873,"guid":"e68f8efb-fea0-4423-a90e-ccf1f67750f9","subtype":"command","commandType":"auto","position":20.78125,"command":"println(two(2))\nprintln(two(\"Test\"))\nprintln(two(\"Long String\"))\nprintln(two(3.0d))\nprintln(two('a'))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">literal for two\nLength is less than 5\nYou entered a string\nIt's a Double\nUnexpected input\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492259983788,"submitTime":1492259983782,"finishTime":1492259983944,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"af91643e-70f1-48b2-94be-2af1937b8c6c"},{"version":"CommandV1","origId":3627984262107871,"guid":"f15691fd-810d-4ff5-958d-cc1bd81d4f72","subtype":"command","commandType":"auto","position":20.8125,"command":"%md\nYou can chain several partial functions together using the following syntax: `pf1 orElse pf2 orElse pf3 ...`. A `MathError` is only thrown if none of the partial functions match the input.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"65051efc-c4f8-48e8-8b78-118b96a6322f"},{"version":"CommandV1","origId":755287174841069,"guid":"7a3198ca-18dd-472e-8ba5-d7d01ee40c13","subtype":"command","commandType":"auto","position":20.9375,"command":"%md\n## Ranges\n\nA `Range` literal makes it very easy to create sequences of numbers and characters. You can create ranges with an inclusive and exclusive upper bounds and arbitrary intervals. Let's explore this through some examples:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"9f33b39f-ea7d-4d67-b3c8-1bb1ee745b73"},{"version":"CommandV1","origId":3627984262107865,"guid":"3934d5a6-0e81-46de-806e-b77913bc2bfa","subtype":"command","commandType":"auto","position":21.3125,"command":"1 to 10","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res23: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260036446,"submitTime":1492260036440,"finishTime":1492260036805,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"5736e921-fdc0-4411-9cb2-01b513e62fac"},{"version":"CommandV1","origId":3627984262107866,"guid":"28b8fae3-b734-4ec1-844c-3bc27a6ccf85","subtype":"command","commandType":"auto","position":21.5,"command":"val range1 = 1 until 10\nrange1.foreach(println)\nrange1(0)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">1\n2\n3\n4\n5\n6\n7\n8\n9\nrange1: scala.collection.immutable.Range = Range(1, 2, 3, 4, 5, 6, 7, 8, 9)\nres24: Int = 1\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260082017,"submitTime":1492260082010,"finishTime":1492260082336,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"7d42ff29-9655-4a27-9c97-2f09e73226d5"},{"version":"CommandV1","origId":3627984262107867,"guid":"8f8a20a3-b678-4524-9bb0-b0d3e49dff53","subtype":"command","commandType":"auto","position":21.59375,"command":"1f to 11f by 3.1f","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res25: scala.collection.immutable.NumericRange[Float] = NumericRange(1.0, 4.1, 7.2, 10.299999)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260179897,"submitTime":1492260179889,"finishTime":1492260180229,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"23bdb024-443b-44b4-9838-02f6697965c2"},{"version":"CommandV1","origId":3627984262107869,"guid":"5a809b7d-ab8f-4915-9c6c-b19857d37b17","subtype":"command","commandType":"auto","position":21.6171875,"command":"val x = ('a' to 'g' by 3).toArray","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">x: Array[Char] = Array(a, d, g)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260212314,"submitTime":1492260212307,"finishTime":1492260212607,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"8581f105-8506-4c35-ace3-487f4e557701"},{"version":"CommandV1","origId":3627984262107868,"guid":"f1c5a8e6-a6f1-48b2-9ff6-d3009412580c","subtype":"command","commandType":"auto","position":21.640625,"command":"for (i <- 1 to 3) println(i)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">1\n2\n3\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260254080,"submitTime":1492260254074,"finishTime":1492260254354,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"801406c9-fb4d-4e65-9c43-24b3661a08b2"},{"version":"CommandV1","origId":99369287466328,"guid":"f37b137c-b2d1-43d7-9496-bf169a97f4e3","subtype":"command","commandType":"auto","position":21.6875,"command":"%md\n\n##while and do-while Loops\n\nThese loops are somewhat similiar to Java. Let's write a do-while loop that uses a mutable variable and counts up to 10:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"e91d0b82-dac5-41d6-9083-e0d27181db6c"},{"version":"CommandV1","origId":99369287466329,"guid":"d28ad3a3-68e6-42e0-bf4e-e3fb8e56e60c","subtype":"command","commandType":"auto","position":21.8125,"command":"var count = 0\n\ndo{\n count += 1\n println(count)\n} while (count < 10)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\ncount: Int = 10\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260279986,"submitTime":1492260279980,"finishTime":1492260280146,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"ca5496e4-ec59-4e72-b592-37dd3f28ec91"},{"version":"CommandV1","origId":3627984262107881,"guid":"e25c1599-1270-43bb-8f56-2c92b5f7b8c1","subtype":"command","commandType":"auto","position":22.3125,"command":"%md\n## Collections\nScala defines several collection classes:</br>\n### Base Classes\n- `Iterable` (collections you can iterate on)\n- `Seq` (ordered Sequences)\n- `Set`\n- `Map` (Lookup Data Structure)\n### Immutable Collections\n- `List` (linked list, fast sequential access)\n- `Stream` (same as `List`, except that the tail is evaluated only on demand)\n- `Vector` (array-like type, implemented as tree of blocks, provides fast random access)\n- `Range` (ordered sequence of integers with equal spacing)\n- `String` (Java type, implicitly converted to a character sequence, so you can treat every string like a `Seq[Char]`)\n- `Map` (collection that maps keys to values)\n- `Set` (collection without duplicate elements)\n### Mutable Collections\n- `Array` (fixed-size sequential collection of elements of the same type)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184825445,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"283a9d8d-6f53-4840-a64d-52517741a13e"},{"version":"CommandV1","origId":3627984262107882,"guid":"23cee2f0-3f0e-49c0-b4ab-48f534e67e5a","subtype":"command","commandType":"auto","position":22.5625,"command":"val m = Map(1 -> \"Scala\", 2 -> \"Spark\")\nprintln(m(1))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Scala\nm: scala.collection.immutable.Map[Int,String] = Map(1 -> Scala, 2 -> Spark)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260365282,"submitTime":1492260365275,"finishTime":1492260365742,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"eb270cb5-f18e-4e0f-a7ba-e383506ccfb4"},{"version":"CommandV1","origId":3627984262107883,"guid":"b65bf5e7-85ff-4dc4-bfaf-85f7b7a2c2a7","subtype":"command","commandType":"auto","position":22.6875,"command":"%md\n### Functional Combinators\nThe most notables are:\n- `map`: Apply a function over each element in the list\n- `flatten`: It collapses one level of nested structure\n- `flatMap`: It's map + flatten\n- `foreach`: It's like map but returns nothing","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"94f94ad5-48ef-4b5d-92f2-f34bc4811a12"},{"version":"CommandV1","origId":3627984262107884,"guid":"f6f4d4fe-0350-4a73-914c-bb5d979d049e","subtype":"command","commandType":"auto","position":22.75,"command":"val numbers = List(1, 2, 3, 4)\n","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">numbers: List[Int] = List(1, 2, 3, 4)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260426477,"submitTime":1492260426470,"finishTime":1492260426781,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"767d8da3-6576-40f7-ab2d-ae117adfccaf"},{"version":"CommandV1","origId":3627984262107885,"guid":"cfb7a3fc-76f4-4f30-8343-034491b4cc29","subtype":"command","commandType":"auto","position":22.78125,"command":"numbers.map(i => i*2)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res29: List[Int] = List(2, 4, 6, 8)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260459696,"submitTime":1492260459689,"finishTime":1492260460019,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"807a91eb-39b4-4fa5-9f87-ee951b2424ec"},{"version":"CommandV1","origId":3627984262107886,"guid":"c95576a6-b642-4e29-8cbd-f113d09397ae","subtype":"command","commandType":"auto","position":22.796875,"command":"List(List(1,2),List(3,4)).flatten","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res30: List[Int] = List(1, 2, 3, 4)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260479779,"submitTime":1492260479772,"finishTime":1492260480073,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"03522963-fae6-4928-9a2c-3cb940a039f4"},{"version":"CommandV1","origId":3627984262107977,"guid":"3bdb8934-5e6c-45d6-a5b3-1c72bbd57145","subtype":"command","commandType":"auto","position":22.80126953125,"command":"%md\n## Arrays","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492184826147,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"87443d7c-fb3d-4b81-bcc4-de3f9e1ce806"},{"version":"CommandV1","origId":3627984262107888,"guid":"03fe0707-1fc9-4d79-a596-2dcdc1a45781","subtype":"command","commandType":"auto","position":22.8056640625,"command":"val array: Array[String] = new Array(5)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">array: Array[String] = Array(null, null, null, null, null)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260529678,"submitTime":1492260529672,"finishTime":1492260529814,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"c054bd5e-b248-4237-a0fc-5e8481090c17"},{"version":"CommandV1","origId":3627984262107889,"guid":"ef5feeb3-3f01-443d-9919-c0d686d5d999","subtype":"command","commandType":"auto","position":22.80908203125,"command":"%md\nWe've declared the `array` variable with the `val` keyword so it's immutable. This means that the `array` reference cannot be changed to point to a different `Array`, but the array elements themselves are mutable and can be changed.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":1492232677695,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"6381e2fe-a46e-463c-8a76-d9d9a8917d12"},{"version":"CommandV1","origId":3627984262107890,"guid":"eb122ded-9a97-4b26-9feb-8c540967d1c3","subtype":"command","commandType":"auto","position":22.810791015625,"command":"array(0) = \"Hello\"","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\"></div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260552079,"submitTime":1492260552072,"finishTime":1492260552217,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"22e8bb96-858c-45cf-abe9-6020dac2f418"},{"version":"CommandV1","origId":3627984262107891,"guid":"11073e14-f62a-498f-b46b-024df0b3357a","subtype":"command","commandType":"auto","position":22.8116455078125,"command":"array(4) = \"Bye\"","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\"></div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1492260558888,"submitTime":1492260558881,"finishTime":1492260559008,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"f699b841-61fd-4f2a-afaa-d943ab360c5d"},{"version":"CommandV1","origId":3627984262107892,"guid":"b6f4eba8-2d64-49ec-9d82-8da70ce4651b","subtype":"command","commandType":"auto","position":22.81207275390625,"command":"array.foreach(println)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Hello\nnull\nnull\nnull\nBye\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\">Unclosed block</div>","error":null,"workflows":[],"startTime":1492260583153,"submitTime":1492260583146,"finishTime":1492260583384,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"58128d47-1ee6-4565-96fb-e18e90cf407f"},{"version":"CommandV1","origId":154374227189979,"guid":"51cd30c9-3d93-47b5-9e21-ef3f93d85714","subtype":"command","commandType":"auto","position":22.812286376953125,"command":"%md\n##Options","commandVersion":0,"state":"error","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"4f65bc0d-2439-468a-babe-e3d019869a9a"},{"version":"CommandV1","origId":154374227189980,"guid":"34178f53-cf83-4d66-848b-bbfcf9d30d7a","subtype":"command","commandType":"auto","position":22.812393188476562,"command":"%md\n**Options** are the way Scala deals with the situations where we might have a `null` value. Scala's `Option` is an abstract class which has two concrete subclasses:\n- `Some`, for when we have a value, and\n- `None`, for when we don't have a value - when it's `null`.</br>\nThe following example demonstrates everything you'll probably need to know about Options:","commandVersion":0,"state":"error","results":null,"errorSummary":"<div class=\"ansiout\"><console>:34: error: not found: value **\n **Options**\n ^\n<console>:34: error: not found: value **\n **Options**\n ^\n</div>","error":null,"workflows":[],"startTime":1493641822622,"submitTime":1493641822622,"finishTime":1493641861097,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"b8b60c7e-b2d7-4900-b4a6-df2391509d7e"},{"version":"CommandV1","origId":154374227189983,"guid":"d21a5ede-7908-4056-99e9-b8f903582b27","subtype":"command","commandType":"auto","position":22.81244659423828,"command":"val stateCapitals = Map(\n \"Alabama\" -> \"Montgomery\",\n \"Alaska\" -> \"Juneau\",\n \"Wyoming\" -> \"Cheyenne\"\n)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">stateCapitals: scala.collection.immutable.Map[String,String] = Map(Alabama -> Montgomery, Alaska -> Juneau, Wyoming -> Cheyenne)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1493642159816,"submitTime":1493642159796,"finishTime":1493642160850,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"a3b77c05-9cd9-40a1-9a36-e2b47232d40a"},{"version":"CommandV1","origId":154374227189984,"guid":"05c46b4e-c313-4b71-9dbd-88af96d168f5","subtype":"command","commandType":"auto","position":22.81247329711914,"command":"println( \"Get the capitals wrapped in Options:\" )\nprintln( \"Alabama: \" + stateCapitals.get(\"Alabama\") )\nprintln( \"Wyoming: \" + stateCapitals.get(\"Wyoming\") )\nprintln( \"Unknown: \" + stateCapitals.get(\"Unknown\") )","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">Get the capitals wrapped in Options:\nAlabama: Some(Montgomery)\nWyoming: Some(Cheyenne)\nUnknown: None\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"workflows":[],"startTime":1493642230421,"submitTime":1493642230405,"finishTime":1493642230664,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"9164ad92-f729-4b07-8fee-d25a017a3cb8"},{"version":"CommandV1","origId":154374227189987,"guid":"9ec26f55-24b8-4c23-a235-4a5488b64dfd","subtype":"command","commandType":"auto","position":22.812479972839355,"command":"%md\nThe `Map.get` method returns an `Option[T]` (`T` is `String` in our case). By returning an Option, we can’t “forget” that we have to verify that something was returned.</br>\nAs you can see, when we ask for an entry that does not exist, the `None` object will be returned - instead of a `null` keyword.","commandVersion":0,"state":"error","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"90681154-c615-463f-b999-5bd4b120819d"},{"version":"CommandV1","origId":154374227189985,"guid":"28f72f33-ecf7-4f70-acbf-34b473e8c686","subtype":"command","commandType":"auto","position":22.81248664855957,"command":"%md\nNow we call `get` or `getOrElse` on each `Option` instance to retrieve the value it contains. Using `get` can be dangerous, because if the returned object is a `None`, calling `get` on it would result in a `NoSuchElementException`.</br>\nIt's better to use `getOrElse`, where you can specify a default return value in case of a `None`.</br>\nLet's see this in action:","commandVersion":0,"state":"error","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"1667ae1f-f618-4faa-81b1-6701c7bbc103"},{"version":"CommandV1","origId":154374227189988,"guid":"48ea69fc-3dda-478c-930b-6d4c9a44aeac","subtype":"command","commandType":"auto","position":22.812493324279785,"command":"println( \"Get the capitals themselves out of the Options:\" )\nprintln( \"Alabama: \" + stateCapitals.get(\"Alabama\").get )\nprintln( \"Wyoming: \" + stateCapitals.get(\"Wyoming\").getOrElse(\"Oops!\") )\nprintln( \"Unknown: \" + stateCapitals.get(\"Unknown\").getOrElse(\"Oops2!\") )\n\n//let's play with fire!\nprintln( \"Unknown: \" + stateCapitals.get(\"Unknown\").get)","commandVersion":0,"state":"error","results":{"type":"html","data":"<div class=\"ansiout\">Get the capitals themselves out of the Options:\nAlabama: Montgomery\nWyoming: Cheyenne\nUnknown: Oops2!\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"java.util.NoSuchElementException: None.get","error":"<div class=\"ansiout\">\tat scala.None$.get(Option.scala:347)\n\tat scala.None$.get(Option.scala:345)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$read$$iw$$iw$$iw$$iw$$iw$$iw.<init>(<console>:42)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$read$$iw$$iw$$iw$$iw$$iw.<init>(<console>:53)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$read$$iw$$iw$$iw$$iw.<init>(<console>:55)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$read$$iw$$iw$$iw.<init>(<console>:57)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$read$$iw$$iw.<init>(<console>:59)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$read$$iw.<init>(<console>:61)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$eval$.$print$lzycompute(<console>:7)\n\tat line4d2cf6b435ee4f7b8ed71edb49b3d23b39.$eval$.$print(<console>:6)</div>","workflows":[],"startTime":1493642879271,"submitTime":1493642879271,"finishTime":1493642879487,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"d558ab87-7f33-483d-a93b-176c412ae9ef"},{"version":"CommandV1","origId":154374227189989,"guid":"d61097e6-6816-4b13-a30b-890b74e72860","subtype":"command","commandType":"auto","position":22.812496662139893,"command":"%md\nDid you see that? 😁 </br>\nSo, always use `getOrElse` to make sure you don't run into exceptions.","commandVersion":0,"state":"error","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"457653b0-5c0f-4376-b650-dc55fc6ed098"},{"version":"CommandV1","origId":3627984262107878,"guid":"b6ebbc8c-7ce8-4f0f-acd7-0509288030ba","subtype":"command","commandType":"auto","position":22.8125,"command":"%md\n# Acknowledgements\n\nThe design and content of this notebook has been **heavily** influenced by the following (In some cases, direct content has been placed here).</br>\nWe thank these authors and contributors for their awesome material!</br>\n\n- “**[Programming Scala, Second Edition](https://deanwampler.github.io/books/programmingscala2.html)** by Dean Wampler and Alex Payne. Copyright 2015 Kevin Dean Wampler and Alex Payne, 978-1-491-94985-6”\n- [Dr. Amir H. Payberah](http://www.cs.ox.ac.uk/people/amir.payberah/web/index.html)'s **[Slides](http://www.cs.ox.ac.uk/people/amir.payberah/web/files/download/slides/sharif.pdf)** and **[Courses](https://www.sics.se/~amir/id2221/)**, most notably his [workshop](http://www.paravid.com/lecture/an-introduction-to-data-intensive-computing-platforms) at Sharif Univ. of Technology in August 2016\n- [Scala Cheat Sheet](https://github.com/lampepfl/progfun-wiki/blob/gh-pages/CheatSheet.md) by the guys at **EPFL's Programming Methods Laboratory**","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"workflows":[],"startTime":0,"submitTime":0,"finishTime":0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"a user","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"streamStates":{},"nuid":"2e454c0b-8754-4c2a-8c5e-d41fedd2b16c"}],"dashboards":[],"guid":"37a01e54-c4aa-44b6-9311-cef34bf7c3ed","globalVars":{},"iPythonMetadata":null,"inputWidgets":{}};</script>
<script
src="https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/js/notebook-main.js"
onerror="window.mainJsLoadError = true;"></script>
</head>
<body>
<script>
if (window.mainJsLoadError) {
var u = 'https://databricks-prod-cloudfront.cloud.databricks.com/static/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/js/notebook-main.js';
var b = document.getElementsByTagName('body')[0];
var c = document.createElement('div');
c.innerHTML = ('<h1>Network Error</h1>' +
'<p><b>Please check your network connection and try again.</b></p>' +
'<p>Could not load a required resource: ' + u + '</p>');
c.style.margin = '30px';
c.style.padding = '20px 50px';
c.style.backgroundColor = '#f5f5f5';
c.style.borderRadius = '5px';
b.appendChild(c);
}
</script>
</body>
</html>