class Allomorph
Error ReportCollection examples

Dual value number and string

The Allomorph class is a common parent class for Raku's dual value types: ComplexStr, IntStr, NumStr, RatStr.

The dual value types (often referred to as allomorphs) 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:

As a subclass of both a Numeric class and 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 parent class- or Str-only variants:

Please see the Numerics page for a more complete description on how to work with these allomorphs.

# Methods

## method ACCEPTS

If the a parameter is Numeric (including another allomorph), checks if invocant's Numeric value ACCEPTS a. If the a parameter is Str, checks if invocant's Str value ACCEPTS a. If the a parameter is anything else, checks if both Numeric and Str values of the invocant ACCEPTS a.

## method Bool

Returns False if the invocant is numerically 0, otherwise returns True. The Str value of the invocant is not considered.

Note: For the Allomorph subclass RatStr also see Rational.Bool.

## method chomp

Calls Str.chomp on the invocant's Str value.

## method chop

Calls Str.chop on the invocant's Str value.

## method comb

Calls Str.comb on the invocant's Str value.

## method fc

Calls Str.fc on the invocant's Str value.

## method flip

Calls Str.flip on the invocant's Str value.

## method lc

Calls Str.lc on the invocant's Str value.

## method pred

Calls Numeric.pred on the invocant's numeric value.

## method raku

Return a representation of the object that can be used via EVAL to reconstruct the value of the object.

## method samecase

Calls Str.samecase on the invocant's Str value.

## method samemark

Calls Str.samemark on the invocant's Str value.

## method split

Calls Str.split on the invocant's Str value.

## method Str

Returns the Str value of the invocant.

## method subst

Calls Str.subst on the invocant's Str value.

## method subst-mutate

Calls Str.subst-mutate on the invocant's Str value.

## method substr

Calls Str.substr on the invocant's Str value.

## method substr-rw

Calls Str.substr-rw on the invocant's Str value.

## method succ

Calls Numeric.succ on the invocant's numeric value.

## method tc

Calls Str.tc on the invocant's Str value.

## method tclc

Calls Str.tclc on the invocant's Str value.

## method trim

Calls Str.trim on the invocant's Str value.

Calls Str.trim-leading on the invocant's Str value.

## method trim-trailing

Calls Str.trim-trailing on the invocant's Str value.

## method uc

Calls Str.uc on the invocant's Str value.

## method WHICH

Returns an object of type ValueObjAt which uniquely identifies the object.

# Operators

## infix cmp

Compare two Allomorph objects. The comparison is done on the Numeric value first and then on the Str value. If you want to compare in a different order then you would coerce to an Numeric or Str value first:

## infix eqv

Returns True if the two Allomorph \$a and \$b are of the same type, their Numeric values are equivalent and their Str values are also equivalent. Returns False otherwise.