Last active
December 29, 2015 05:59
-
-
Save mariogleichmann/7626098 to your computer and use it in GitHub Desktop.
Pointless Programming, using nested function composition while referring to an Argument more than one time
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') ... | |
// (a) Non-Pointless-way - this compiles: | |
def pairF[A,B,C,D]( f : A => B, g : C => D ) : (A,C) => (B,D) = (x,y) => ( f(x), g(y) ) | |
// (b) Pointless way - this doesn't compile | |
// two helper functions, extracting the first / second component of a Pair | |
def fst[A,B]( p : (A,B) ) :A = p._1 | |
def snd[A,B]( p : (A,B) ) :B = p._2 | |
// WON'T COMPILE: | |
//def pairF2[A,B,C,D]( f : A => B, g : C => D ) : (A,C) => (B,D) = ( f o fst ) & ( g o snd ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or this one, in order to respect your initial signature: