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
// Note that this interface is defined with default/package access | |
interface PackageAccessInterface { | |
void doSomething(); | |
} | |
public class ProvidesPackageAccessInterface { | |
private String someVariable; | |
private String someOtherVariable; | |
private String yetAnotherVariable; |
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
using System; | |
namespace EventRecorderExample { | |
public class Customer { | |
private IEventRecorder eventRecorder = EventRecorder.CreateEventRecorder(); | |
// rest of implementation... | |
} | |
public class EventRecorder : IEventRecorder { |
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
fun <A,B,C> curry(function: (A,B) -> C): (A) -> (B) -> C { | |
return fun (a: A): (B) -> C { | |
return fun (b: B): C { | |
return function(a, b) | |
} | |
} | |
} |
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
import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.describe | |
import org.jetbrains.spek.api.dsl.it | |
import org.junit.Assert | |
fun fibonacci(n: Int): Int { | |
tailrec fun loop(n: Int, previous: Int, current: Int): Int { | |
return when(n) { | |
0 -> previous | |
else -> loop(n-1, current, previous+current) |
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
fun fibonacci2(n: Int): Int { | |
tailrec fun loop(n: Int, previous: Int, current: Int): Int { | |
return if( n == 0 ) { | |
previous | |
} else { | |
loop(n-1, current, previous+current) | |
} | |
} | |
return loop(n, 0, 1) |
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
import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.describe | |
import org.jetbrains.spek.api.dsl.it | |
import kotlin.test.assertFalse | |
import kotlin.test.assertTrue | |
fun <A> isSorted(array: Array<A>, ordered: (A,A) -> Boolean): Boolean { | |
tailrec fun loop(current: Int): Boolean { | |
when(current) { | |
array.size -> return true |
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
class Ch02Test : Spek({ | |
val expectedValues = arrayOf(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, | |
987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811) | |
fun runFibonacciTests(function: (Int) -> Int) { | |
it("should return the correct first value") { | |
assertEquals(0, function(0)) | |
} | |
it("should return the correct values in expectedValues") { |
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
import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.describe | |
import org.jetbrains.spek.api.dsl.it | |
import org.junit.Assert.assertEquals | |
fun <A,B,C> curry(function: (A,B) -> C): (A) -> ((B) -> C) { | |
return fun (a: A): (B) -> C { | |
return fun (b: B): C { | |
return function(a, b) | |
} |
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
import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.describe | |
import org.jetbrains.spek.api.dsl.it | |
import org.junit.Assert.assertEquals | |
fun <A,B,C> uncurry(function: (A) -> ((B) -> C)): (A,B) -> C { | |
return fun(a: A, b: B): C { | |
return function(a)(b) | |
} | |
} |
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
package com.tartner.vertx | |
import io.vertx.core.eventbus.* | |
import io.vertx.kotlin.coroutines.* | |
import kotlinx.coroutines.experimental.* | |
import java.util.* | |
sealed class CodeMessage<T: Any>(val block: suspend () -> T) | |
class ReturnValueCodeMessage<T: Any>(block: suspend () -> T): CodeMessage<T>(block) | |
class UnitCodeMessage(block: suspend () -> Unit): CodeMessage<Unit>(block) |
OlderNewer