Any.to
totarget_type
Group: Conversions
Documentation
Generic conversion of an arbitrary Enso value to requested type. Delegates to appropriate .from
conversion method, if it exists. If such method doesn't exist, No_Such_Conversion
panic is raised.
Arguments
target_type
: the requested type.
Examples
Following code defines conversion of a Complex
type to a Number
by computing absolute distance from 0
. The code yields 5.0
:
type Complex
Value re:Number im:Number
Number.from (that:Complex) = that.re*that.re+that.im*that.im . sqrt
Complex.Value 3 4 . to Number
.from
conversion methods may have additional arguments
with default values. Thus the conversion from Complex
to
Number
may take additional argument:
type Complex
Value re:Number im:Number
Number.from (that:Complex) = that.re*that.re+that.im*that.im . sqrt
Complex.Value 3 4 . to Number
type Complex
Value re:Number im:Number
Number.from (that:Complex) (ignore_im:Boolean=False) = case ignore_im of
False -> that.re*that.re+that.im*that.im . sqrt
True -> that.re
yields_3 = Complex.Value 3 4 . to Number ignore_im=True
yields_5 = Complex.Value 3 4 . to Number ignore_im=False
default5 = Complex.Value 3 4 . to Number