txt: ## allomorph.md
  class Allomorph
  
  Dual value number and string
  
  ```raku
  class Allomorph is Str { }
  ```
  
  The `Allomorph` class is a common parent class for Raku's dual value types: [`ComplexStr`](/type/ComplexStr), [`IntStr`](/type/IntStr), [`NumStr`](/type/NumStr), [`RatStr`](/type/RatStr).
  
  The dual value types (often referred to as [allomorphs](/language/glossary#Allomorph)) allow for the representation of a value as both a string and a numeric type. Typically they will be created for you when the context is "stringy" but they can be determined to be numbers, such as in some [quoting constructs](/language/quoting):
  
  ```raku
  my $c = <42+0i>;  say $c.^name; # OUTPUT: «ComplexStr␤»
  my $i = <42>;     say $i.^name; # OUTPUT: «IntStr␤»
  my $n = <42.1e0>; say $n.^name; # OUTPUT: «NumStr␤»
  my $r = <42.1>;   say $r.^name; # OUTPUT: «RatStr␤»
  ```
  
  As a subclass of both a [`Numeric`](/type/Numeric) class and [`Str`](/type/Str), via the `Allomorph` class, an allomorph will be accepted where either is expected. However, an allomorph does not share object identity with its [`Numeric`](/type/Numeric) parent class- or [`Str`](/type/Str)-only variants:
  
  ```raku
  my ($complex-str, $int-str, $num-str, $rat-str)
             = < 42+0i 42 42e10 42.1 >;
  
  my (Complex $complex, Int $int, Num $num, Rat $rat)
             =  $complex-str, $int-str, $num-str, $rat-str;  # OK!
  
  my Str @strings
             =  $complex-str, $int-str, $num-str, $rat-str;  # OK!
  
  # ∈ operator cares about object identity
  say 42+0i ∈ < 42+0i 42 42e10 42.1 >;  # OUTPUT: «False␤»
  say 42    ∈ < 42+0i 42 42e10 42.1 >;  # OUTPUT: «False␤»
  say 42e10 ∈ < 42+0i 42 42e10 42.1 >;  # OUTPUT: «False␤»
  say 42.1  ∈ < 42+0i 42 42e10 42.1 >;  # OUTPUT: «False␤»
  
  ```
  
  Please see [the Numerics page](/language/numerics#Allomorphs) for a more complete description on how to work with these allomorphs.
  
  # [Methods](#class_Allomorph "go to top of document")[§](#Methods "direct link")
  
  ## [method ACCEPTS](#class_Allomorph "go to top of document")[§](#method_ACCEPTS "direct link")
  
  ```raku
  multi method ACCEPTS(Allomorph:D: Any:D \a)
  ```
  
  If the `a` parameter is [`Numeric`](/type/Numeric) (including another [allomorph](/language/glossary#Allomorph)), checks if invocant's [`Numeric`](/type/Numeric) value [ACCEPTS](/type/Numeric#method_ACCEPTS) `a`. If the `a` parameter is [`Str`](/type/Str), checks if invocant's [`Str`](/type/Str) value [ACCEPTS](/type/Str#method_ACCEPTS) `a`. If the `a` parameter is anything else, checks if both [`Numeric`](/type/Numeric) and [`Str`](/type/Str) values of the invocant `ACCEPTS` `a`.
  
  ```raku
  say "5.0" ~~ <5>; # OUTPUT: «False␤»
  say 5.0   ~~ <5>; # OUTPUT: «True␤»
  say <5.0> ~~ <5>; # OUTPUT: «True␤»
  ```
  
  ## [method Bool](#class_Allomorph "go to top of document")[§](#method_Bool "direct link")
  
  ```raku
  multi method Bool(::?CLASS:D:)
  ```
  
  Returns `False` if the invocant is numerically `0`, otherwise returns `True`. The [`Str`](/type/Str) value of the invocant is not considered.
  
  **Note**: For the `Allomorph` subclass [`RatStr`](/type/RatStr) also see [`Rational.Bool`](/type/Rational#method_Bool).
  
  ## [method chomp](#class_Allomorph "go to top of document")[§](#method_chomp "direct link")
  
  ```raku
  method chomp(Allomorph:D:)
  ```
  
  Calls [`Str.chomp`](/type/Str#routine_chomp) on the invocant's [`Str`](/type/Str) value.
  
  ## [method chop](#class_Allomorph "go to top of document")[§](#method_chop "direct link")
  
  ```raku
  method chop(Allomorph:D: |c)
  ```
  
  Calls [`Str.chop`](/type/Str#routine_chop) on the invocant's [`Str`](/type/Str) value.
  
  ## [method comb](#class_Allomorph "go to top of document")[§](#method_comb "direct link")
  
  ```raku
  method comb(Allomorph:D: |c)
  ```
  
  Calls [`Str.comb`](/type/Str#routine_comb) on the invocant's [`Str`](/type/Str) value.
  
  ## [method fc](#class_Allomorph "go to top of document")[§](#method_fc "direct link")
  
  ```raku
  method fc(Allomorph:D:)
  ```
  
  Calls [`Str.fc`](/type/Str#routine_fc) on the invocant's [`Str`](/type/Str) value.
  
  ## [method flip](#class_Allomorph "go to top of document")[§](#method_flip "direct link")
  
  ```raku
  method flip(Allomorph:D:)
  ```
  
  Calls [`Str.flip`](/type/Str#routine_flip) on the invocant's [`Str`](/type/Str) value.
  
  ## [method lc](#class_Allomorph "go to top of document")[§](#method_lc "direct link")
  
  ```raku
  method lc(Allomorph:D:)
  ```
  
  Calls [`Str.lc`](/type/Str#routine_lc) on the invocant's [`Str`](/type/Str) value.
  
  ## [method pred](#class_Allomorph "go to top of document")[§](#method_pred "direct link")
  
  ```raku
  method pred(Allomorph:D:)
  ```
  
  Calls [`Numeric.pred`](/type/Numeric#method_pred) on the invocant's numeric value.
  
  ## [method raku](#class_Allomorph "go to top of document")[§](#method_raku "direct link")
  
  ```raku
  multi method raku(Allomorph:D:)
  ```
  
  Return a representation of the object that can be used via [`EVAL`](/routine/EVAL) to reconstruct the value of the object.
  
  ## [method samecase](#class_Allomorph "go to top of document")[§](#method_samecase "direct link")
  
  ```raku
  method samecase(Allomorph:D: |c)
  ```
  
  Calls [`Str.samecase`](/type/Str#method_samecase) on the invocant's [`Str`](/type/Str) value.
  
  ## [method samemark](#class_Allomorph "go to top of document")[§](#method_samemark "direct link")
  
  ```raku
  method samemark(Allomorph:D: |c)
  ```
  
  Calls [`Str.samemark`](/type/Str#routine_samemark) on the invocant's [`Str`](/type/Str) value.
  
  ## [method split](#class_Allomorph "go to top of document")[§](#method_split "direct link")
  
  ```raku
  method split(Allomorph:D: |c)
  ```
  
  Calls [`Str.split`](/type/Str#routine_split) on the invocant's [`Str`](/type/Str) value.
  
  ## [method Str](#class_Allomorph "go to top of document")[§](#method_Str "direct link")
  
  ```raku
  method Str(Allomorph:D:)
  ```
  
  Returns the [`Str`](/type/Str) value of the invocant.
  
  ## [method subst](#class_Allomorph "go to top of document")[§](#method_subst "direct link")
  
  ```raku
  method subst(Allomorph:D: |c)
  ```
  
  Calls [`Str.subst`](/type/Str#method_subst) on the invocant's [`Str`](/type/Str) value.
  
  ## [method subst-mutate](#class_Allomorph "go to top of document")[§](#method_subst-mutate "direct link")
  
  ```raku
  method subst-mutate(Allomorph:D \SELF: |c)
  ```
  
  Calls [`Str.subst-mutate`](/type/Str#method_subst-mutate) on the invocant's [`Str`](/type/Str) value.
  
  ## [method substr](#class_Allomorph "go to top of document")[§](#method_substr "direct link")
  
  ```raku
  method substr(Allomorph:D: |c)
  ```
  
  Calls [`Str.substr`](/type/Str#routine_substr) on the invocant's [`Str`](/type/Str) value.
  
  ## [method substr-rw](#class_Allomorph "go to top of document")[§](#method_substr-rw "direct link")
  
  ```raku
  method substr-rw(Allomorph:D \SELF: $start = 0, $want = Whatever)
  ```
  
  Calls [`Str.substr-rw`](/type/Str#method_substr-rw) on the invocant's [`Str`](/type/Str) value.
  
  ## [method succ](#class_Allomorph "go to top of document")[§](#method_succ "direct link")
  
  ```raku
  method succ(Allomorph:D:)
  ```
  
  Calls [`Numeric.succ`](/type/Numeric#method_succ) on the invocant's numeric value.
  
  ## [method tc](#class_Allomorph "go to top of document")[§](#method_tc "direct link")
  
  ```raku
  method tc(Allomorph:D:)
  ```
  
  Calls [`Str.tc`](/type/Str#routine_tc) on the invocant's [`Str`](/type/Str) value.
  
  ## [method tclc](#class_Allomorph "go to top of document")[§](#method_tclc "direct link")
  
  ```raku
  method tclc(Allomorph:D:)
  ```
  
  Calls [`Str.tclc`](/type/Str#routine_tclc) on the invocant's [`Str`](/type/Str) value.
  
  ## [method trim](#class_Allomorph "go to top of document")[§](#method_trim "direct link")
  
  ```raku
  method trim(Allomorph:D:)
  ```
  
  Calls [`Str.trim`](/type/Str#method_trim) on the invocant's [`Str`](/type/Str) value.
  
  ## [method trim-leading](#class_Allomorph "go to top of document")[§](#method_trim-leading "direct link")
  
  ```raku
  method trim-leading(Allomorph:D:)
  ```
  
  Calls [`Str.trim-leading`](/type/Str#method_trim-leading) on the invocant's [`Str`](/type/Str) value.
  
  ## [method trim-trailing](#class_Allomorph "go to top of document")[§](#method_trim-trailing "direct link")
  
  ```raku
  method trim-trailing(Allomorph:D:)
  ```
  
  Calls [`Str.trim-trailing`](/type/Str#method_trim-trailing) on the invocant's [`Str`](/type/Str) value.
  
  ## [method uc](#class_Allomorph "go to top of document")[§](#method_uc "direct link")
  
  ```raku
  method uc(Allomorph:D:)
  ```
  
  Calls [`Str.uc`](/type/Str#routine_uc) on the invocant's [`Str`](/type/Str) value.
  
  ## [method WHICH](#class_Allomorph "go to top of document")[§](#method_WHICH "direct link")
  
  ```raku
  multi method WHICH(Allomorph:D:)
  ```
  
  Returns an object of type [`ValueObjAt`](/type/ValueObjAt) which uniquely identifies the object.
  
  ```raku
  my $f = <42.1e0>;
  say $f.WHICH;     # OUTPUT: «NumStr|Num|42.1|Str|42.1e0␤»
  ```
  
  # [Operators](#class_Allomorph "go to top of document")[§](#Operators "direct link")
  
  ## [infix cmp](#class_Allomorph "go to top of document")[§](#infix_cmp "direct link")
  
  ```raku
  multi infix:<cmp>(Allomorph:D $a, Allomorph:D $b)
  ```
  
  Compare two `Allomorph` objects. The comparison is done on the [`Numeric`](/type/Numeric) value first and then on the [`Str`](/type/Str) value. If you want to compare in a different order then you would coerce to a [`Numeric`](/type/Numeric) or [`Str`](/type/Str) value first:
  
  ```raku
  my $f = IntStr.new(42, "smaller");
  my $g = IntStr.new(43, "larger");
  say $f cmp $g;          # OUTPUT: «Less␤»
  say $f.Str cmp $g.Str;  # OUTPUT: «More␤»
  ```
  
  ## [infix eqv](#class_Allomorph "go to top of document")[§](#infix_eqv "direct link")
  
  ```raku
  multi infix:<eqv>(Allomorph:D $a, Allomorph:D $b --> Bool:D)
  ```
  
  Returns `True` if the two `Allomorph` `$a` and `$b` are of the same type, their [`Numeric`](/type/Numeric) values are [equivalent](/routine/eqv) and their [`Str`](/type/Str) values are also [equivalent](/routine/eqv). Returns `False` otherwise.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `Allomorph`
  
  
  
  raku-type-graph
  
  
  
  Allomorph
  Allomorph
  
  
  Str
  Str
  
  
  Allomorph->Str
  
  
  
  Mu
  Mu
  
  
  Any
  Any
  
  
  Any->Mu
  
  
  
  Cool
  Cool
  
  
  Cool->Any
  
  
  
  Stringy
  Stringy
  
  
  Str->Cool
  
  
  
  Str->Stringy
  
  
  
  Numeric
  Numeric
  
  
  Real
  Real
  
  
  Real->Numeric
  
  
  
  Int
  Int
  
  
  Int->Cool
  
  
  
  Int->Real
  
  
  
  IntStr
  IntStr
  
  
  IntStr->Allomorph
  
  
  
  IntStr->Int
  
  
  
  Num
  Num
  
  
  Num->Cool
  
  
  
  Num->Real
  
  
  
  NumStr
  NumStr
  
  
  NumStr->Allomorph
  
  
  
  NumStr->Num
  
  
  
  Complex
  Complex
  
  
  Complex->Cool
  
  
  
  Complex->Numeric
  
  
  
  ComplexStr
  ComplexStr
  
  
  ComplexStr->Allomorph
  
  
  
  ComplexStr->Complex
  
  
  
  Rational
  Rational
  
  
  Rational->Real
  
  
  
  Rat
  Rat
  
  
  Rat->Cool
  
  
  
  Rat->Rational
  
  
  
  RatStr
  RatStr
  
  
  RatStr->Allomorph
  
  
  
  RatStr->Rat
  
  [Expand chart above](/assets/typegraphs/Allomorph.svg)
  