forked from lamdor/scala-koans
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,33 @@ | ||
package org.scalakoans | ||
|
||
import support.KoanSuite | ||
|
||
class AboutStructuralTypes extends KoanSuite { | ||
|
||
koan ("stuctural types") { | ||
def sayHello(person: {def name: String}) = "Hello, " + person.name | ||
|
||
case class Person(name: String) | ||
|
||
val p = new Person("Lou") | ||
|
||
sayHello(p) should be(__) | ||
|
||
case class Person2 | ||
val p2 = new Person2 | ||
meditate | ||
//sayHello(p2) should be(__) | ||
} | ||
|
||
koan ("defined structural type") { | ||
type HasName = {def name: String} | ||
|
||
def sayHello(person: HasName) = "Hello, " + person.name | ||
|
||
case class Person(name: String) | ||
|
||
val p = new Person("Lou") | ||
sayHello(p) should be(__) | ||
} | ||
|
||
} |
This file contains 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