trait
ByName[ByNameType] extends Serializable
Type Members
-
abstract
type
Value
Abstract Value Members
-
abstract
def
extract(byName: ByNameType): Value
-
abstract
def
make(byName: ⇒ Value): ByNameType
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
def
+(other: String): String
-
def
->[B](y: B): (ByName[ByNameType], B)
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
def
ensuring(cond: (ByName[ByNameType]) ⇒ Boolean, msg: ⇒ Any): ByName[ByNameType]
-
def
ensuring(cond: (ByName[ByNameType]) ⇒ Boolean): ByName[ByNameType]
-
def
ensuring(cond: Boolean, msg: ⇒ Any): ByName[ByNameType]
-
def
ensuring(cond: Boolean): ByName[ByNameType]
-
-
-
def
finalize(): Unit
-
def
formatted(fmtstr: String): String
-
final
def
getClass(): Class[_]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
-
def
→[B](y: B): (ByName[ByNameType], B)
Inherited by implicit conversion any2stringadd from
ByName[ByNameType] to any2stringadd[ByName[ByNameType]]
Inherited by implicit conversion StringFormat from
ByName[ByNameType] to StringFormat[ByName[ByNameType]]
Inherited by implicit conversion Ensuring from
ByName[ByNameType] to Ensuring[ByName[ByNameType]]
Inherited by implicit conversion ArrowAssoc from
ByName[ByNameType] to ArrowAssoc[ByName[ByNameType]]
A type class for convert between by-name type and normal by-value type.
Installation
This ByName type class provide an extension method extract for ByName.=> types via implicit view, which can be import as follow:
import com.thoughtworks.feature.ByName.ops._
Author:
杨博 (Yang Bo) <[email protected]>
The by-name type
When using this ByName type class, you should make sure the type parameter
ByNameType
is an abstract type, in case of Scala compiler bugs. You can use a trick similar to C++'s Pimpl Idiom to create opacity abstract typesNow
IntByName
is an abstract type with underlying=> Int
type.Given a by-name parameter of the return value of
getInt()
,when
getInt
returns 42,getInt.when.once returns 42
then the value of the the by-name parameter should be 42;
boxedByName.extract should be(42)
when
getInt
returns 144,getInt.when.once returns 144
then the value of the the by-name parameter should be 144.
boxedByName.extract should be(144)