summaryrefslogtreecommitdiff
path: root/src/utils/FunctionUtils.scala
blob: 3d6610cf9bbb0bbac78e7c943b0417847c986c8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package ixee.cryptopals.utils

object FunctionUtils {
  // Because doing (_ f _).tupled confuses the inferencer...
  def tup[A, B, C](f: (A, B) => C): ((A, B)) => C = f.tupled

  def ident[A]: A => A = { x => x }

  implicit class Compositor[A, B](f: A => B) {
    def :|[C](g: B => C): A => C = f.andThen(g)
  }

  implicit class Tap[A](x: A) {
    def tap(f: A => Any): A = {
      f(x)
      x
    }
  }
}