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
bd = branch --delete | |
bm = branch --merged | |
cbr = rev-parse --abbrev-ref HEAD | |
cm = commit -m | |
co = checkout | |
cob = checkout -b | |
comit = commit | |
g = grep --break --heading --line-number | |
lol = log --pretty=oneline --abbrev-commit --graph --decorate | |
ship = push |
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
sealed class Either<out L, out R> { | |
data class Left<out L>(val l: L) : Either<L, Nothing>() | |
data class Right<out R>(val r: R) : Either<Nothing, R>() | |
} | |
fun asdf() { | |
val p = Promise<Int> { resolve, reject -> | |
resolve(Either.Left(4)) | |
} |
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 android.databinding.BindingAdapter | |
import android.support.design.widget.TextInputEditText | |
import android.support.design.widget.TextInputLayout | |
data class FormData<out D, R>( | |
val data: D, | |
val reason: R?, | |
private val _reasonToString: (R?) -> String = { "$it" } | |
) { | |
val isValid = reason != null |
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
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import Control.Compose | |
import Control.Monad.Trans.State.Lazy | |
import Data.Char |
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
data Tree a = Branch (Tree a) (Tree a) | Leaf a deriving Show | |
instance Functor Tree where | |
fmap fn (Branch l r) = Branch (fmap fn l) (fmap fn r) | |
fmap fn (Leaf a) = Leaf $ fn a | |
instance Applicative Tree where | |
(<*>) (Leaf fn) t = fmap fn t | |
(<*>) (Branch l r) t = Branch (l <*> t) (r <*> t) | |
pure = Leaf |
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
data Parser = WebParser | DbParser | |
class ParseStrategy p where | |
parse :: p -> String -> String | |
instance ParseStrategy Parser where | |
parse WebParser s = "code for parsing web stuff goes here" | |
parse DbParser s = "code for parsing db stuff goes here" | |
fromDB = parse DbParser |
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 <T> List<T>.scan(fn: (T, T) -> T): List<T> { | |
return if (this.isEmpty()) this | |
else this.drop(1).fold(listOf(this.first()), { acc, item -> | |
acc.plus(fn(acc.last(), item)) | |
}) | |
} | |
println((1..5).toList().scan { x, y -> x + y }) |
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
private class ValueEventListenerToEmitter(private val emitter: Emitter<DataSnapshot>) : ValueEventListener { | |
override fun onCancelled(error: DatabaseError) { | |
emitter.onError(error.toException()) | |
} | |
override fun onDataChange(snapshot: DataSnapshot) { | |
emitter.onNext(snapshot) | |
} | |
} |
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
interface View { | |
fun clicks(): Observable<Unit> | |
} | |
interface Model { | |
fun submits(): Observable<Unit> | |
} | |
class Presenter(val view: View, val model: Model) { | |
fun setUp() { |
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
@Test | |
fun debounce_test() { | |
// TestScheduler lets us control time ;) | |
val testScheduler = TestScheduler() | |
// This basically represents a button. | |
val testClicks = PublishSubject<Long>() | |
// This'll let us verify our interactions | |
val testSubscriber = TestSubscriber<Long>() |
NewerOlder