mirror of
https://github.com/jlengrand/scala-intro-for-java-guys.git
synced 2026-03-10 08:41:22 +00:00
Initializes repo
This commit is contained in:
74
.gitignore
vendored
Normal file
74
.gitignore
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
# Created by http://www.gitignore.io
|
||||
|
||||
### Scala ###
|
||||
*.class
|
||||
*.log
|
||||
|
||||
# sbt specific
|
||||
.cache/
|
||||
.history/
|
||||
.lib/
|
||||
dist/*
|
||||
target/
|
||||
lib_managed/
|
||||
src_managed/
|
||||
project/boot/
|
||||
project/plugins/project/
|
||||
|
||||
# Scala-IDE specific
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# End of https://www.gitignore.io/api/intellij
|
||||
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
Hello
|
||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
9
.idea/modules.xml
generated
Normal file
9
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/root.iml" filepath="$PROJECT_DIR$/.idea/modules/root.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/root-build.iml" filepath="$PROJECT_DIR$/.idea/modules/root-build.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
78
.idea/modules/root-build.iml
generated
Normal file
78
.idea/modules/root-build.iml
generated
Normal file
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="root-build" external.linked.project.path="$MODULE_DIR$/../../project" external.root.project.path="$MODULE_DIR$/../.." external.system.id="SBT" sbt.imports="$00da4602aefa8690a887.root, _root_.sbt.plugins.IvyPlugin, _root_.sbt.plugins.JvmPlugin, _root_.sbt.plugins.CorePlugin, _root_.sbt.plugins.JUnitXmlReportPlugin, _root_.sbt.plugins.Giter8TemplatePlugin, sbt._, Keys._, dsl._" sbt.resolvers="https://repo1.maven.org/maven2/|maven|public, http://repo.typesafe.com/typesafe/releases|maven|typesafe-releases, C:\Users\jll\.ivy2\cache|ivy|Local cache" type="SBT_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/../../project/target/idea-classes" />
|
||||
<output-test url="file://$MODULE_DIR$/../../project/target/idea-test-classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../../project">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../project" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/../../project/project/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/../../project/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library name="SBT: sbt-and-plugins">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/lib/jansi.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/lib/jline.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/lib/scala-compiler.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/lib/scala-library.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/lib/scala-reflect.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/actions-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/api-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/apply-macro-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/cache-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/classfile-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/classpath-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/collections-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/command-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/compile-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/compiler-integration-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/compiler-interface-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/compiler-ivy-integration-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/completion-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/control-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/cross-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/incremental-compiler-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/io-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/ivy-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/ivy-2.3.0-sbt-2cf13e211b2cb31f0d3b317289dca70eca3362f6.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/jansi-1.11.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/jawn-parser_2.10-0.6.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/jline-2.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/jsch-0.1.50.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/json4s-ast_2.10-3.2.10.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/json4s-core_2.10-3.2.10.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/json4s-support_2.10-0.6.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/launcher-interface-1.0.0-M1.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/logging-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/logic-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/main-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/main-settings-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/paranamer-2.6.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/persist-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/process-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/quasiquotes_2.10-2.0.1.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/relation-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/run-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/sbinary_2.10-0.4.2.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/sbt-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/scala-pickling_2.10-0.10.1.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/scala-reflect-2.10.6.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/serialization_2.10-0.1.2.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/task-system-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/tasks-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/template-resolver-0.1.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/test-agent-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/test-interface-1.0.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/testing-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/tracking-0.13.13.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.13/xsbti/interface-0.13.13.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
33
.idea/modules/root.iml
generated
Normal file
33
.idea/modules/root.iml
generated
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="root" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="SBT" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/../../target/scala-2.12/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/../../target/scala-2.12/test-classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../..">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/scala" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/scala-2.12" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.12/src_managed/main" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/scala" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/scala-2.12" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.12/src_managed/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.12/resource_managed/main" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.12/resource_managed/test" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/../../target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/../../target/resolution-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/../../target/streams" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="SBT: org.scala-lang:scala-library:2.12.1:jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="SBT: org.scalatest:scalatest_2.12:3.0.1:jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="SBT: org.scalactic:scalactic_2.12:3.0.1:jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="SBT: org.scala-lang.modules:scala-xml_2.12:1.0.5:jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="SBT: org.scala-lang.modules:scala-parser-combinators_2.12:1.0.4:jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="SBT: org.scala-lang:scala-reflect:2.12.1:jar" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
21
.idea/sbt.xml
generated
Normal file
21
.idea/sbt.xml
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ScalaSbtSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<SbtProjectSettings>
|
||||
<option name="createEmptyContentRootDirectories" value="true" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="jdk" value="1.8" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/project" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="sbtVersion" value="0.13.13" />
|
||||
<option name="useAutoImport" value="true" />
|
||||
<option name="useOurOwnAutoImport" value="true" />
|
||||
</SbtProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/scala_compiler.xml
generated
Normal file
6
.idea/scala_compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ScalaCompilerConfiguration">
|
||||
<profile name="SBT 1" modules="root" />
|
||||
</component>
|
||||
</project>
|
||||
12
build.sbt
Normal file
12
build.sbt
Normal file
@@ -0,0 +1,12 @@
|
||||
import Dependencies._
|
||||
|
||||
lazy val root = (project in file(".")).
|
||||
settings(
|
||||
inThisBuild(List(
|
||||
organization := "com.example",
|
||||
scalaVersion := "2.12.1",
|
||||
version := "0.1.0-SNAPSHOT"
|
||||
)),
|
||||
name := "Hello",
|
||||
libraryDependencies += scalaTest % Test
|
||||
)
|
||||
5
project/Dependencies.scala
Normal file
5
project/Dependencies.scala
Normal file
@@ -0,0 +1,5 @@
|
||||
import sbt._
|
||||
|
||||
object Dependencies {
|
||||
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1"
|
||||
}
|
||||
1
project/build.properties
Normal file
1
project/build.properties
Normal file
@@ -0,0 +1 @@
|
||||
sbt.version=0.13.13
|
||||
44
src/main/scala/example/Comparable.scala
Normal file
44
src/main/scala/example/Comparable.scala
Normal file
@@ -0,0 +1,44 @@
|
||||
package example
|
||||
|
||||
/**
|
||||
* Created by jll on 3/4/2017.
|
||||
*/
|
||||
trait Ord {
|
||||
def < (that: Any): Boolean
|
||||
def <=(that: Any): Boolean = (this < that) || (this == that)
|
||||
def > (that: Any): Boolean = !(this <= that)
|
||||
def >=(that: Any): Boolean = !(this < that)
|
||||
}
|
||||
|
||||
class Date(y: Int, m: Int, d: Int) extends Ord {
|
||||
def year = y
|
||||
def month = m
|
||||
def day = d
|
||||
override def toString(): String = year + "-" + month + "-" + day
|
||||
|
||||
override def equals(that: Any): Boolean =
|
||||
that.isInstanceOf[Date] && {
|
||||
val o = that.asInstanceOf[Date]
|
||||
o.day == day && o.month == month && o.year == year
|
||||
}
|
||||
|
||||
def <(that: Any): Boolean = {
|
||||
if (!that.isInstanceOf[Date])
|
||||
sys.error("cannot compare " + that + " and a Date")
|
||||
val o = that.asInstanceOf[Date]
|
||||
(year < o.year) ||
|
||||
(year == o.year && (month < o.month ||
|
||||
(month == o.month && day < o.day)))
|
||||
}
|
||||
}
|
||||
|
||||
object Thing2{
|
||||
def main(args: Array[String]){
|
||||
|
||||
var d = new Date(2016, 12, 31)
|
||||
var d2 = new Date(2017, 11, 11)
|
||||
|
||||
println(d2 > d)
|
||||
|
||||
}
|
||||
}
|
||||
19
src/main/scala/example/ComplexNumbers.scala
Normal file
19
src/main/scala/example/ComplexNumbers.scala
Normal file
@@ -0,0 +1,19 @@
|
||||
package example
|
||||
|
||||
/**
|
||||
* Created by jll on 3/3/2017.
|
||||
*/
|
||||
object ComplexNumbers {
|
||||
def main(args: Array[String]) {
|
||||
val c = new Complex(1.2, 3.4)
|
||||
println("imaginary part: " + c.im)
|
||||
println(c)
|
||||
}
|
||||
}
|
||||
|
||||
class Complex(real: Double, imaginary: Double) {
|
||||
def re = real
|
||||
def im = imaginary
|
||||
override def toString() =
|
||||
"" + re + (if (im < 0) "" else "+") + im + "i"
|
||||
}
|
||||
18
src/main/scala/example/Genericity.scala
Normal file
18
src/main/scala/example/Genericity.scala
Normal file
@@ -0,0 +1,18 @@
|
||||
package example
|
||||
|
||||
/**
|
||||
* Created by jll on 3/4/2017.
|
||||
*/
|
||||
object IntegerReference {
|
||||
def main(args: Array[String]) {
|
||||
val cell = new Reference[Int]
|
||||
cell.set(13)
|
||||
println("Reference contains the half of " + (cell.get * 2))
|
||||
}
|
||||
}
|
||||
|
||||
class Reference[T] {
|
||||
private var contents: T = _
|
||||
def set(value: T) { contents = value }
|
||||
def get: T = contents
|
||||
}
|
||||
9
src/main/scala/example/Hello.scala
Normal file
9
src/main/scala/example/Hello.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package example
|
||||
|
||||
object Hello extends Greeting with App {
|
||||
println(greeting)
|
||||
}
|
||||
|
||||
trait Greeting {
|
||||
lazy val greeting: String = "hello"
|
||||
}
|
||||
14
src/main/scala/example/Timer.scala
Normal file
14
src/main/scala/example/Timer.scala
Normal file
@@ -0,0 +1,14 @@
|
||||
package example
|
||||
|
||||
/**
|
||||
* Created by jll on 3/3/2017.
|
||||
*/
|
||||
object Timer {
|
||||
def oncePerSecond(callback: () => Unit) {
|
||||
while (true) { callback(); Thread sleep 1000 }
|
||||
}
|
||||
|
||||
def main(args: Array[String]) {
|
||||
oncePerSecond(() => println("time flies like an arrow..."))
|
||||
}
|
||||
}
|
||||
34
src/main/scala/example/Tree.scala
Normal file
34
src/main/scala/example/Tree.scala
Normal file
@@ -0,0 +1,34 @@
|
||||
package example
|
||||
|
||||
/**
|
||||
* Created by jll on 3/4/2017.
|
||||
*/
|
||||
abstract class Tree
|
||||
case class Sum(l: Tree, r: Tree) extends Tree
|
||||
case class Var(n: String) extends Tree
|
||||
case class Const(v: Int) extends Tree
|
||||
|
||||
object Thing {
|
||||
type Environment = String => Int
|
||||
|
||||
def eval(t: Tree, env: Environment): Int = t match {
|
||||
case Sum(l, r) => eval(l, env) + eval(r, env)
|
||||
case Var(n) => env(n)
|
||||
case Const(v) => v
|
||||
}
|
||||
|
||||
def derive(t: Tree, v: String): Tree = t match {
|
||||
case Sum(l, r) => Sum(derive(l, v), derive(r, v))
|
||||
case Var(n) if (v == n) => Const(1)
|
||||
case _ => Const(0)
|
||||
}
|
||||
|
||||
def main(args: Array[String]) {
|
||||
val exp: Tree = Sum(Sum(Var("x"),Var("x")),Sum(Const(7),Var("y")))
|
||||
val env: Environment = { case "x" => 5 case "y" => 7 }
|
||||
println("Expression: " + exp)
|
||||
println("Evaluation with x=5, y=7: " + eval(exp, env))
|
||||
println("Derivative relative to x:\n " + derive(exp, "x"))
|
||||
println("Derivative relative to y:\n " + derive(exp, "y"))
|
||||
}
|
||||
}
|
||||
9
src/test/scala/example/HelloSpec.scala
Normal file
9
src/test/scala/example/HelloSpec.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package example
|
||||
|
||||
import org.scalatest._
|
||||
|
||||
class HelloSpec extends FlatSpec with Matchers {
|
||||
"The Hello object" should "say hello" in {
|
||||
Hello.greeting shouldEqual "hello"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user