Trait/Object

com.thoughtworks.feature

PartialApply

Related Docs: object PartialApply | package feature

Permalink

trait PartialApply[F, ParameterName <: String with Singleton] extends Serializable

A dependent type class that bind the specific parameter of ParameterName to F

Imports

import com.thoughtworks.feature.PartialApply.ops._

This will enable the partialApply method for any functions

Author:

杨博 (Yang Bo) <[email protected]>

F

The function type to be partially apply

Source
PartialApply.scala
Examples:
  1. Given a function with three parameters.

    val f = { (v1: Int, v2: Int, v3: Int) => (v1 + v2) * v3 }

    When partially applying the second parameter.

    val partiallyApplied = f.partialApply(v2 = 2)

    And applying the rest parameters.

    val result = partiallyApplied(v3 = 3, v1 = 1)

    Then the result should be the same as applying at once.

    result should be(f(1, 2, 3))
  2. ,
  3. A function with refined parameters can partially apply.

    val f: ((Int, Double, String) => String) { def apply(i: Int, d: Double, s: String): String } = { (i, d, s) =>
      (i * d) + s
    }
    f.partialApply(s = "seconds").apply(i = 60, d = 1.125) should be(f(s = "seconds", i = 60, d = 1.125))
  4. ,
  5. Partial applying can be chained.

    val f = { (v1: Int, v2: Int, v3: Int) => (v1 + v2) * v3 }
    f.partialApply(v2 = 2).partialApply(v3 = 3).partialApply(v1 = 1).apply() should be(f(1, 2, 3))
  6. ,
  7. Function objects can partially apply.

    object f extends ((Int, Double, String) => String) {
      def apply(i: Int, d: Double, s: String): String = {
        (i * d) + s
      }
    }
    f.partialApply(s = "seconds").apply(i = 60, d = 1.125) should be(f(s = "seconds", i = 60, d = 1.125))
  8. ,
  9. Case class companion can partially apply.

    case class MyCaseClass(i: Int, d: Double, s: String)
    MyCaseClass.partialApply(s = "seconds").apply(i = 60, d = 1.125) should be(MyCaseClass(s = "seconds", i = 60, d = 1.125))
  10. ,
  11. Call-by-name functions can partially apply.

    def foo(v1: => String, v2: Int) = v1 + v2
    val callByNameFunction = foo _
    PartialApply.materialize[callByNameFunction.type, "v1"].apply(callByNameFunction, "1").apply(v2 = 2) should be(foo(v1 = "1", v2 = 2))
Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. PartialApply
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Parameter

    Permalink
  2. abstract type Rest

    Permalink

Abstract Value Members

  1. abstract def apply(f: F, parameter: Parameter): Rest

    Permalink

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to any2stringadd[PartialApply[F, ParameterName]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (PartialApply[F, ParameterName], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to ArrowAssoc[PartialApply[F, ParameterName]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def ensuring(cond: (PartialApply[F, ParameterName]) ⇒ Boolean, msg: ⇒ Any): PartialApply[F, ParameterName]

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to Ensuring[PartialApply[F, ParameterName]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  9. def ensuring(cond: (PartialApply[F, ParameterName]) ⇒ Boolean): PartialApply[F, ParameterName]

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to Ensuring[PartialApply[F, ParameterName]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: Boolean, msg: ⇒ Any): PartialApply[F, ParameterName]

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to Ensuring[PartialApply[F, ParameterName]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: Boolean): PartialApply[F, ParameterName]

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to Ensuring[PartialApply[F, ParameterName]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to StringFormat[PartialApply[F, ParameterName]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  16. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  17. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  19. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  20. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  21. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  23. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  24. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. def [B](y: B): (PartialApply[F, ParameterName], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from PartialApply[F, ParameterName] to ArrowAssoc[PartialApply[F, ParameterName]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from PartialApply[F, ParameterName] to any2stringadd[PartialApply[F, ParameterName]]

Inherited by implicit conversion StringFormat from PartialApply[F, ParameterName] to StringFormat[PartialApply[F, ParameterName]]

Inherited by implicit conversion Ensuring from PartialApply[F, ParameterName] to Ensuring[PartialApply[F, ParameterName]]

Inherited by implicit conversion ArrowAssoc from PartialApply[F, ParameterName] to ArrowAssoc[PartialApply[F, ParameterName]]

Ungrouped