Skip to content

Instantly share code, notes, and snippets.

Avatar
🎨
painting boxes

Paco pakoito

🎨
painting boxes
View GitHub Profile
View gist:7802ab6a2389721519a1f0d6da691d31
private fun loggedInMenuUi(menu: Menu, rootView: View, checkoutCartStream: Stream<Bla>, startActivity: () -> Unit) {
val alertMenuItem = menu.findItem(R.id.activity_main_alerts_menu_item)
val rootView = (alertMenuItem.actionView as FrameLayout).apply {
setOnClickListener {
startActivity()
}
}
val redCircle: FrameLayout = rootView.findViewById(R.id.view_alert_red_circle)
View is there better way
when (info) {
null -> {
return unauthorized()
}
else -> {
val validInfo = validator.validateInfo(info)
when (validInfo) {
is Either.Right -> {
if (!validInfo.b.authorised) {
View comonads.js
const Day = ({ get, left, right }) => {
const map = f => Day ({
get: f (extract()),
left, right
})
const extend = f =>
Day ({
get: (left, right) => f (Day ({ get, left, right })),
@pakoito
pakoito / Test.kt
Created Apr 8, 2018
Applicatives, Functors and Monads using Kotlin and Arrow
View Test.kt
import arrow.core.*
import arrow.data.k
import arrow.syntax.applicative.tupled
import arrow.syntax.functor.map
import arrow.typeclasses.binding
typealias IntFunction = (Int) -> Int
fun IntFunction.map(g: IntFunction) = { it: Int -> this(g(it)) }
View specs-example.rs
extern crate specs;
use specs::Component;
use specs::VecStorage;
use specs::System;
use specs::WriteStorage;
use specs::ReadStorage;
use specs::World;
use specs::DispatcherBuilder;
use specs::RunNow;
@pakoito
pakoito / Recursive
Last active Feb 15, 2018
Recursive datatypes in Kotlin
View Recursive
sealed class NaturalNum
object Zero: NaturalNum()
class PlusOne<N: NaturalNum>(): NaturalNum()
fun num(zero: Zero) = 0
fun num(one: PlusOne<Zero>) = 1
@pakoito
pakoito / lwo.kt
Last active Jan 17, 2018
Lightweight Option
View lwo.kt
inline fun <A, B> A?.fold(crossinline fn: () -> B, crossinline f: (A) -> B): B =
if (this == null) fn() else f(this)
inline fun <A, B> A?.map(crossinline f: (A) -> B): B? = fold({ null }, f)
inline fun <A> A?.orElse(crossinline fn: () -> A): A = fold(fn, { it })
View KECS.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
data family Component a :: *
data instance Component Health = HealthC
data instance Component Stamina = StaminaC
View Advanced-FP-with-Scala.md

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
View ECS
data ComponentR a = ComponentR
{ entity :: EntityId
, info :: InfoR a
}
data InfoR a = InfoR
{ get :: a
}
data World = World
You can’t perform that action at this time.