-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8f5efd2
commit 4247c6e
Showing
14 changed files
with
796 additions
and
45 deletions.
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 |
---|---|---|
|
@@ -29,4 +29,3 @@ proguard/ | |
# Captures | ||
captures/ | ||
out/ | ||
/.gradle/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,35 @@ | ||
package main.kotlin | ||
|
||
/** | ||
* Created by Lazysoul on 2016. 12. 14.. | ||
*/ | ||
sealed class Either<L : Any, R : Any> { | ||
|
||
var isLeft: Boolean = false | ||
var isRight: Boolean = false | ||
|
||
var left: Left<L, Nothing>? = null | ||
var right: Right<Nothing, R>? = null | ||
abstract fun get(): Any | ||
|
||
class Left<L : Any, R : Any>(val value: L) : Either<L, R>() { | ||
init { | ||
isLeft = true | ||
} | ||
|
||
override fun get(): L { | ||
return value | ||
} | ||
|
||
} | ||
|
||
class Right<L : Any, R : Any>(val value: R) : Either<L, R>() { | ||
init { | ||
isRight = true | ||
} | ||
|
||
override fun get(): R { | ||
return value | ||
} | ||
} | ||
} |
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,29 @@ | ||
package test.kotlin | ||
|
||
import main.kotlin.Either | ||
import main.kotlin.Either.Left | ||
import main.kotlin.Either.Right | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
/** | ||
* Created by Lazysoul on 2016. 12. 14.. | ||
*/ | ||
class EitherTest { | ||
|
||
@Test fun leftTest() { | ||
val left: Either<String, Int> = Left("test") | ||
assertEquals("test", left.get()) | ||
assertEquals(true, left.isLeft) | ||
assertEquals(false, left.isRight) | ||
assertEquals(null, left.right?.get()) | ||
} | ||
|
||
@Test fun rightTest() { | ||
val right: Either<String, Int> = Right(6) | ||
assertEquals(6, right.get()) | ||
assertEquals(false, right.isLeft) | ||
assertEquals(true, right.isRight) | ||
assertEquals(null, right.left?.get()) | ||
} | ||
} |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.