txt: ## cool.md
  ## Chunk 3 of 3
   [Str.subst](/type/Str#method_subst).
  
  ## [method trans](#class_Cool "go to top of document")[§](#method_trans "direct link")
  
  ```raku
  method trans(|)
  ```
  
  Coerces the invocant to [`Str`](/type/Str) and calls [Str.trans](/type/Str#method_trans)
  
  ## [method IO](#class_Cool "go to top of document")[§](#method_IO "direct link")
  
  ```raku
  method IO(--> IO::Path:D)
  ```
  
  Coerces the invocant to [`IO::Path`](/type/IO/Path).
  
  ```raku
  .say for '.'.IO.dir;        # gives a directory listing
  
  ```
  
  ## [method sprintf](#class_Cool "go to top of document")[§](#method_sprintf "direct link")
  
  ```raku
  method sprintf(*@args)
  ```
  
  Returns a string according to a series of [format directives](/type/independent-routines#Directives) that are common in many languages; the object will be the format string, while the supplied arguments will be what's going to be formatted according to it.
  
  ```raku
  "% 6s".sprintf('Þor').say; # OUTPUT: «   Þor␤»
  
  ```
  
  ## [method printf](#class_Cool "go to top of document")[§](#method_printf "direct link")
  
  ```raku
  method printf(*@args)
  ```
  
  Uses the object, as long as it is a [format string](/type/independent-routines#Directives), to format and print the arguments
  
  ```raku
  "%.8f".printf(now - now ); # OUTPUT: «-0.00004118»
  
  ```
  
  ## [method Complex](#class_Cool "go to top of document")[§](#method_Complex "direct link")
  
  ```raku
  multi method Complex()
  ```
  
  Coerces the invocant to a [`Numeric`](/type/Numeric) and calls its [`.Complex`](/routine/Complex) method. [Fails](/routine/fail) if the coercion to a [`Numeric`](/type/Numeric) cannot be done.
  
  ```raku
  say 1+1i.Complex;         # OUTPUT: «1+1i␤»
  say π.Complex;            # OUTPUT: «3.141592653589793+0i␤»
  say <1.3>.Complex;        # OUTPUT: «1.3+0i␤»
  say (-4/3).Complex;       # OUTPUT: «-1.3333333333333333+0i␤»
  say "foo".Complex.^name;  # OUTPUT: «Failure␤»
  ```
  
  ## [method FatRat](#class_Cool "go to top of document")[§](#method_FatRat "direct link")
  
  ```raku
  multi method FatRat()
  ```
  
  Coerces the invocant to a [`Numeric`](/type/Numeric) and calls its [`.FatRat`](/routine/FatRat) method. [Fails](/routine/fail) if the coercion to a [`Numeric`](/type/Numeric) cannot be done.
  
  ```raku
  say 1+0i.FatRat;          # OUTPUT: «1␤»
  say 2e1.FatRat;           # OUTPUT: «20␤»
  say 1.3.FatRat;           # OUTPUT: «1.3␤»
  say (-4/3).FatRat;        # OUTPUT: «-1.333333␤»
  say "foo".FatRat.^name;   # OUTPUT: «Failure␤»
  ```
  
  ## [method Int](#class_Cool "go to top of document")[§](#method_Int "direct link")
  
  ```raku
  multi method Int()
  ```
  
  Coerces the invocant to a [`Numeric`](/type/Numeric) and calls its [`.Int`](/routine/Int) method. [Fails](/routine/fail) if the coercion to a [`Numeric`](/type/Numeric) cannot be done.
  
  ```raku
  say 1+0i.Int;             # OUTPUT: «1␤»
  say <2e1>.Int;            # OUTPUT: «20␤»
  say 1.3.Int;              # OUTPUT: «1␤»
  say (-4/3).Int;           # OUTPUT: «-1␤»
  say "foo".Int.^name;      # OUTPUT: «Failure␤»
  ```
  
  ## [method Num](#class_Cool "go to top of document")[§](#method_Num "direct link")
  
  ```raku
  multi method Num()
  ```
  
  Coerces the invocant to a [`Numeric`](/type/Numeric) and calls its [`.Num`](/routine/Num) method. [Fails](/routine/fail) if the coercion to a [`Numeric`](/type/Numeric) cannot be done.
  
  ```raku
  say 1+0i.Num;             # OUTPUT: «1␤»
  say 2e1.Num;              # OUTPUT: «20␤»
  say (16/9)².Num;          # OUTPUT: «3.1604938271604937␤»
  say (-4/3).Num;           # OUTPUT: «-1.3333333333333333␤»
  say "foo".Num.^name;      # OUTPUT: «Failure␤»
  ```
  
  ## [method Rat](#class_Cool "go to top of document")[§](#method_Rat "direct link")
  
  ```raku
  multi method Rat()
  ```
  
  Coerces the invocant to a [`Numeric`](/type/Numeric) and calls its [`.Rat`](/routine/Rat) method. [Fails](/routine/fail) if the coercion to a [`Numeric`](/type/Numeric) cannot be done.
  
  ```raku
  say 1+0i.Rat;                             # OUTPUT: «1␤»
  say 2e1.Rat;                              # OUTPUT: «20␤»
  say (-4/3).Rat;                           # OUTPUT: «-1.333333␤»
  say "foo".Rat.^name;                      # OUTPUT: «Failure␤»
  say (.numerator, .denominator) for π.Rat; # OUTPUT: «(355 113)␤»
  ```
  
  ## [method Real](#class_Cool "go to top of document")[§](#method_Real "direct link")
  
  ```raku
  multi method Real()
  ```
  
  Coerces the invocant to a [`Numeric`](/type/Numeric) and calls its [`.Real`](/routine/Real) method. [Fails](/routine/fail) if the coercion to a [`Numeric`](/type/Numeric) cannot be done.
  
  ```raku
  say 1+0i.Real;            # OUTPUT: «1␤»
  say 2e1.Real;             # OUTPUT: «20␤»
  say 1.3.Real;             # OUTPUT: «1.3␤»
  say (-4/3).Real;          # OUTPUT: «-1.333333␤»
  say "foo".Real.^name;     # OUTPUT: «Failure␤»
  ```
  
  ## [method UInt](#class_Cool "go to top of document")[§](#method_UInt "direct link")
  
  ```raku
  multi method UInt()
  ```
  
  Coerces the invocant to an [`Int`](/type/Int). [Fails](/routine/fail) if the coercion to an [`Int`](/type/Int) cannot be done or if the [`Int`](/type/Int) the invocant had been coerced to is negative.
  
  ```raku
  say 1+0i.UInt;            # OUTPUT: «1␤»
  say 2e1.UInt;             # OUTPUT: «20␤»
  say 1.3.UInt;             # OUTPUT: «1␤»
  say (-4/3).UInt.^name;    # OUTPUT: «Failure␤»
  say "foo".UInt.^name;     # OUTPUT: «Failure␤»
  ```
  
  ## [method uniparse](#class_Cool "go to top of document")[§](#method_uniparse "direct link")
  
  ```raku
  method uniparse(Cool:D: --> Str:D)
  ```
  
  Available as of the 2021.04 release of the Rakudo compiler.
  
  Coerces the invocant to a [`Str`](/type/Str) and then calls the [uniparse](/type/Str#routine_uniparse) on that. This mostly only makes sense for [`Match`](/type/Match) objects.
  
  ## [method Order](#class_Cool "go to top of document")[§](#method_Order "direct link")
  
  ```raku
  method Order(Cool:D: --> Order:D)
  ```
  
  Available as of the 2022.02 release of the Rakudo compiler.
  
  Coerces the invocant to an [`Int`](/type/Int), and then returns one of the [`Order`](/type/Order) enums: `Less` if negative, `Same` if **0**, `More` if positive.
  
  ## [method Failure](#class_Cool "go to top of document")[§](#method_Failure "direct link")
  
  ```raku
  method Failure(Cool:D: --> Failure:D)
  ```
  
  Available as of the 2022.06 release of the Rakudo compiler.
  
  Creates an [`X::AdHoc`](/type/X/AdHoc) exception with the stringification of the invocant, and coerces that into a [`Failure`](/type/Failure) object. Mainly intended to reduce the bytecode for error branches in code, to increase the chances of hot code getting inlined.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `Cool`
  
  
  
  raku-type-graph
  
  
  
  Cool
  Cool
  
  
  Any
  Any
  
  
  Cool->Any
  
  
  
  Mu
  Mu
  
  
  Any->Mu
  
  
  
  StrDistance
  StrDistance
  
  
  StrDistance->Cool
  
  
  
  Iterable
  Iterable
  
  
  Associative
  Associative
  
  
  Map
  Map
  
  
  Map->Cool
  
  
  
  Map->Iterable
  
  
  
  Map->Associative
  
  
  
  IO
  IO
  
  
  IO::Path
  IO::Path
  
  
  IO::Path->Cool
  
  
  
  IO::Path->IO
  
  
  
  Nil
  Nil
  
  
  Nil->Cool
  
  
  
  Numeric
  Numeric
  
  
  Real
  Real
  
  
  Real->Numeric
  
  
  
  Instant
  Instant
  
  
  Instant->Cool
  
  
  
  Instant->Real
  
  
  
  Positional
  Positional
  
  
  Range
  Range
  
  
  Range->Cool
  
  
  
  Range->Iterable
  
  
  
  Range->Positional
  
  
  
  List
  List
  
  
  List->Cool
  
  
  
  List->Iterable
  
  
  
  List->Positional
  
  
  
  Int
  Int
  
  
  Int->Cool
  
  
  
  Int->Real
  
  
  
  Rational
  Rational
  
  
  Rational->Real
  
  
  
  Rat
  Rat
  
  
  Rat->Cool
  
  
  
  Rat->Rational
  
  
  
  PositionalBindFailover
  PositionalBindFailover
  
  
  Sequence
  Sequence
  
  
  Sequence->PositionalBindFailover
  
  
  
  Seq
  Seq
  
  
  Seq->Cool
  
  
  
  Seq->Iterable
  
  
  
  Seq->Sequence
  
  
  
  Stringy
  Stringy
  
  
  Str
  Str
  
  
  Str->Cool
  
  
  
  Str->Stringy
  
  
  
  FatRat
  FatRat
  
  
  FatRat->Cool
  
  
  
  FatRat->Rational
  
  
  
  Num
  Num
  
  
  Num->Cool
  
  
  
  Num->Real
  
  
  
  Duration
  Duration
  
  
  Duration->Cool
  
  
  
  Duration->Real
  
  
  
  Complex
  Complex
  
  
  Complex->Cool
  
  
  
  Complex->Numeric
  
  
  
  Capture
  Capture
  
  
  Capture->Any
  
  
  
  Match
  Match
  
  
  Match->Cool
  
  
  
  Match->Capture
  
  [Expand chart above](/assets/typegraphs/Cool.svg)
  
  1 [[↑]](#fnret1) *the [comb](/routine/comb) routine is a much better choice for many tasks that in other languages are handled by the `split`.*
  