-
Notifications
You must be signed in to change notification settings - Fork 34
Create scala.yml #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saigeet123
wants to merge
8
commits into
abdheshkumar:master
Choose a base branch
from
saigeet123:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a045306
Create scala.yml
saigeet123 e87e79f
Update README.md
saigeet123 5fe5aa2
Update StructuralTypeApp.scala
saigeet123 317eba9
Merge pull request #1 from saigeet123/test-actions
saigeet123 01dd796
Update scala.yml
saigeet123 1b82935
Update scala.yml
saigeet123 e61d2d4
Update scala.yml
saigeet123 7abfeb4
Update scala.yml
saigeet123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Scala CI | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: self-hosted | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: '11' | ||
distribution: 'adopt' | ||
- name: Run tests | ||
run: sbt test | ||
- name: Run tests | ||
run: sbt dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Scala code examples | ||
|
||
|
||
This repository has my learning scala examples | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1 @@ | ||
object StructuralTypeApp extends App { | ||
//structural types | ||
type JavaCloseable = java.io.Closeable | ||
class HipsterCloseable { | ||
def close(): Unit = println("hipster closeable") | ||
def closeSilently(): Unit = println("hipster silently closeable") | ||
} | ||
|
||
//def closeQuietly(closeable: HipsterCloseable OR JavaCloseable): Unit | ||
type UnifiedCloseable = { | ||
def close(): Unit | ||
} // STRUCTURAL TYPE - Allow working with unrelated type that has common structure | ||
|
||
def closeQuietly(closeable: UnifiedCloseable): Unit = closeable.close() | ||
closeQuietly(new JavaCloseable { | ||
override def close(): Unit = println("JavaCloseable...") | ||
}) | ||
closeQuietly(new HipsterCloseable) | ||
|
||
//TYPE REFINEMENT- Refine existing type(e.g JavaCloseable) with structural type | ||
type AdvanceCloseable = JavaCloseable { | ||
def closeSilently(): Unit | ||
} //Enrich type from JavaCloseable | ||
|
||
class AdvanceJavaCloseable extends JavaCloseable { | ||
override def close(): Unit = println("java's close") | ||
def closeSilently(): Unit = { | ||
close() | ||
println("java closes silently") | ||
} | ||
} | ||
def closeShh(advanceJavaCloseable: AdvanceJavaCloseable) = | ||
advanceJavaCloseable.closeSilently() | ||
closeShh(new AdvanceJavaCloseable) | ||
//closeShh(new HipsterCloseable) // will not compile because HipsterCloseable doesn't originated from JavaCloseable even though it has all the methods | ||
//Using structural types as standalone type | ||
def altClose(closeable: { def close(): Unit }) = closeable.close() | ||
|
||
//type-checking => Duck typing | ||
type SoundMaker = { | ||
def makeSound(): Unit | ||
} | ||
class Dog { | ||
def makeSound() = println("bark!") | ||
} | ||
class Cat { | ||
def makeSound() = println("vroom!") | ||
} | ||
val dog: SoundMaker = new Dog | ||
val cat: SoundMaker = new Cat | ||
|
||
//CAVEAT-structural and refinement type are based on reflection | ||
|
||
trait `CBL(Cons based list)`[+T] { | ||
def head: T | ||
def tail: `CBL(Cons based list)`[T] | ||
} | ||
class Human { | ||
def head: Brain = new Brain | ||
} | ||
class Brain { | ||
override def toString: String = "BRAINZ!" | ||
} | ||
|
||
def f[T](somethingWithAHead: { def head: T }) = | ||
println(somethingWithAHead.head) | ||
/* | ||
f is compatible with a CBL and Human? YES. | ||
*/ | ||
case object CBLNIl extends `CBL(Cons based list)`[Nothing] { | ||
override def head: Nothing = ??? | ||
override def tail: `CBL(Cons based list)`[Nothing] = ??? | ||
} | ||
|
||
case class CBCOns[T](override val head: T, | ||
override val tail: `CBL(Cons based list)`[T]) | ||
extends `CBL(Cons based list)`[T] | ||
f(CBCOns(12, CBLNIl)) | ||
f(new Human) | ||
|
||
object HeadEqualizer { | ||
type Headable[T] = { def head: T } | ||
def ===[T](a: Headable[T], b: Headable[T]): Boolean = a.head == b.head | ||
/* | ||
is compatible with a CBL and Human? Yes | ||
*/ | ||
val brainzList = CBCOns(new Brain, CBLNIl) | ||
val stringsList = CBCOns("Brainz", CBLNIl) | ||
HeadEqualizer.===(brainzList, new Human) //Problem | ||
HeadEqualizer.===(new Human, stringsList) // It is not right and not type safe | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please tell me why you have removed this?