Skip to content

Instantly share code, notes, and snippets.

View mariogleichmann's full-sized avatar

Mario Gleichmann mariogleichmann

View GitHub Profile
@mariogleichmann
mariogleichmann / Pointless Programming
Last active December 29, 2015 05:59
Pointless Programming, using nested function composition while referring to an Argument more than one time
// 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') ...
@mariogleichmann
mariogleichmann / Product Type as Function over sum Type
Created November 15, 2011 16:09
Product type, only based on support for sum type, functions and pattern matching (Product Type as Function over sum Type) ...
// 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._
@mariogleichmann
mariogleichmann / 'Elvis' Operator with Scala Dynamic Trait
Created January 17, 2011 22:31
'Elvis' Operator with Scala Dynamic Trait
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 )
}