txt: ## complexstr.md
  class ComplexStr
  
  Dual value complex number and string
  
  ```raku
  class ComplexStr is Allomorph is Complex {}
  ```
  
  `ComplexStr` is a dual value type, a subclass of both [`Allomorph`](/type/Allomorph), hence [`Str`](/type/Str), and [`Complex`](/type/Complex).
  
  See [`Allomorph`](/type/Allomorph) for further details.
  
  ```raku
  my $complex-str = <42+0i>;
  say $complex-str.^name;             # OUTPUT: «ComplexStr␤»
  
  my Complex $complex = $complex-str; # OK!
  my Str     $str     = $complex-str; # OK!
  
  # ∈ operator cares about object identity
  say 42+0i ∈ <42+0i  55  1>;         # OUTPUT: «False␤»
  
  ```
  
  # [Methods](#class_ComplexStr "go to top of document")[§](#Methods "direct link")
  
  ## [method new](#class_ComplexStr "go to top of document")[§](#method_new "direct link")
  
  ```raku
  method new(Complex $i, Str $s)
  ```
  
  The constructor requires both the [`Complex`](/type/Complex) and the [`Str`](/type/Str) value, when constructing one directly the values can be whatever is required:
  
  ```raku
  my $f = ComplexStr.new(42+0i, "forty two (but complicated)");
  say +$f; # OUTPUT: «42+0i␤»
  say ~$f; # OUTPUT: «"forty two (but complicated)"␤»
  ```
  
  ## [method Capture](#class_ComplexStr "go to top of document")[§](#method_Capture "direct link")
  
  ```raku
  method Capture(ComplexStr:D: --> Capture:D)
  ```
  
  Equivalent to [`Mu.Capture`](/type/Mu#method_Capture).
  
  ## [method Complex](#class_ComplexStr "go to top of document")[§](#method_Complex "direct link")
  
  ```raku
  method Complex
  ```
  
  Returns the [`Complex`](/type/Complex) value of the `ComplexStr`.
  
  ## [method Numeric](#class_ComplexStr "go to top of document")[§](#method_Numeric "direct link")
  
  ```raku
  multi method Numeric(ComplexStr:D: --> Complex:D)
  multi method Numeric(ComplexStr:U: --> Complex:D)
  ```
  
  The `:D` variant returns the numeric portion of the invocant. The `:U` variant issues a warning about using an uninitialized value in numeric context and then returns value `<0+0i>`.
  
  ## [method Real](#class_ComplexStr "go to top of document")[§](#method_Real "direct link")
  
  ```raku
  multi method Real(ComplexStr:D: --> Num:D)
  multi method Real(ComplexStr:U: --> Num:D)
  ```
  
  Coerces the numeric portion of the invocant to [`Num`](/type/Num). If the imaginary part isn't [approximately](/language/operators#infix_≅) zero, coercion [fails](/routine/fail) with [`X::Numeric::Real`](/type/X/Numeric/Real).
  
  The `:D` variant returns the result of that coercion. The `:U` variant issues a warning about using an uninitialized value in numeric context and then returns value `0e0`.
  
  # [Operators](#class_ComplexStr "go to top of document")[§](#Operators "direct link")
  
  ## [infix `===`](#class_ComplexStr "go to top of document")[§](#infix_=== "direct link")
  
  ```raku
  multi infix:<===>(ComplexStr:D $a, ComplexStr:D $b)
  ```
  
  `ComplexStr` Value identity operator. Returns `True` if the [`Complex`](/type/Complex) values of `$a` and `$b` are [identical](/routine/===) and their [`Str`](/type/Str) values are also [identical](/routine/===). Returns `False` otherwise.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `ComplexStr`
  
  
  
  raku-type-graph
  
  
  
  ComplexStr
  ComplexStr
  
  
  Allomorph
  Allomorph
  
  
  ComplexStr->Allomorph
  
  
  
  Complex
  Complex
  
  
  ComplexStr->Complex
  
  
  
  Mu
  Mu
  
  
  Any
  Any
  
  
  Any->Mu
  
  
  
  Cool
  Cool
  
  
  Cool->Any
  
  
  
  Stringy
  Stringy
  
  
  Str
  Str
  
  
  Str->Cool
  
  
  
  Str->Stringy
  
  
  
  Allomorph->Str
  
  
  
  Numeric
  Numeric
  
  
  Complex->Cool
  
  
  
  Complex->Numeric
  
  [Expand chart above](/assets/typegraphs/ComplexStr.svg)
  