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
// connecting / pairing the codomain of two functions | |
def connectF[A,B,C]( f : A => B, g : A => C ) : A => (B,C) = a => ( f(a), g(a) ) | |
// using codomain pairing / and function composition inline | |
implicit class FUtils[A,B]( f : A => B ){ | |
def &[C]( g : A => C ) = connectF( f, g ) | |
def o[C]( g : C => A ) : C => B = f compose g | |
} | |
// connecting / pairing two functions (convert into a 'Bi-Function') ... |
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
// a very simple kind of union type - or you might say 'another Either' | |
object Sum{ | |
abstract trait OR[+A,+B] | |
case class FST[A,B]( a:A ) extends OR[A,B] | |
case class SND[A,B]( b:B ) extends OR[A,B] | |
} | |
// a simple Product type, based on sum types | |
object Product{ | |
import Sum._ |
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
object DynamicElvis { | |
class DynamicImpl( x: AnyRef ) extends Dynamic { | |
def _select_(name: String): DynamicElvis = { | |
val mName = name.substring(0, name.length - 1 ) | |
val mVal = x.getClass.getMethod(mName).invoke( x ) | |
new DynamicElvis( if( mVal != null ) Some( mVal ) else None ) | |
} | |