Skip to content

Instantly share code, notes, and snippets.

@sam
Created March 22, 2016 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam/0e2e81d4e3dad67dc451 to your computer and use it in GitHub Desktop.
Save sam/0e2e81d4e3dad67dc451 to your computer and use it in GitHub Desktop.
Trying to figure out how I can zip both 1-arg functions, and no-arg functions for use in ScalaTest test-fixture "loan" functions.
type FixtureFunction[T] = T => Any
implicit class FixtureFunctionZipper[A](f1: FixtureFunction[A] => Any) {
def zip[B](f2: FixtureFunction[B] => Any): ((A, B) => Any) => Any = { test =>
f1(a => f2(b => test(a, b)))
}
def zip(f2: (Unit => Any) => Any): (A => Any) => Any = { test =>
f1(a => f2(_ => test(a)))
}
}
implicit class CBNFixtureFunctionZipper(f1: (Unit => Any) => Any) {
def zip[A](f2: FixtureFunction[A] => Any): (A => Any) => Any = { test =>
f1(_ => f2(test))
}
def zip(f2: => (Unit => Any) => Any): (=> Any) => Any = { test =>
f1(_ => f2(_ => test))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment