txt: ## bridge.md
  Bridge
  
  Combined from primary sources listed below.
  
  # [In role Rational](#___top "go to top of document")[§](#(role_Rational)_method_Bridge "direct link")
  
  See primary documentation
  [in context](/type/Rational#method_Bridge)
  for **method Bridge**.
  
  ```raku
  method Bridge()
  ```
  
  Returns the number, converted to [`Num`](/type/Num).
  
  # [In Num](#___top "go to top of document")[§](#(Num)_method_Bridge "direct link")
  
  See primary documentation
  [in context](/type/Num#method_Bridge)
  for **method Bridge**.
  
  ```raku
  method Bridge(Num:D:)
  ```
  
  Returns the number.
  
  # [In Int](#___top "go to top of document")[§](#(Int)_method_Bridge "direct link")
  
  See primary documentation
  [in context](/type/Int#method_Bridge)
  for **method Bridge**.
  
  ```raku
  method Bridge(Int:D: --> Num:D)
  ```
  
  Returns the integer converted to [`Num`](/type/Num).
  
  # [In role Real](#___top "go to top of document")[§](#(role_Real)_method_Bridge "direct link")
  
  See primary documentation
  [in context](/type/Real#method_Bridge)
  for **method Bridge**.
  
  ```raku
  method Bridge(Real:D:)
  ```
  
  Default implementation coerces the invocant to [`Num`](/type/Num) and that's the behavior of this method in core `Real` types. This method primarily exist to make it easy to implement custom `Real` types by users, with the `Bridge` method returning *one of* the core `Real` types (*NOT* necessarily a [`Num`](/type/Num)) that best represent the custom `Real` type. In turn, this lets all the core operators and methods obtain a usable value they can work with.
  
  As an example, we can implement a custom `Temperature` type. It has a unit of measure and the value, which are given during instantiation. We can implement custom operators or conversion methods that work with this type. When it comes to regular mathematical operators, however, we can simply use the `.Bridge` method to convert the `Temperature` to Kelvin expressed in one of the core numeric types:
  
  ```raku
  class Temperature is Real {
      has Str:D  $.unit  is required where any <K F C>;
      has Real:D $.value is required;
      method new ($value, :$unit = 'K') { self.bless :$value :$unit }
      # Note: implementing .new() that handles $value of type Temperature is left as an exercise
  
      method Bridge {
          when $!unit eq 'F' { ($!value + 459.67) × 5/9 }
          when $!unit eq 'C' {  $!value + 273.15 }
          $!value
      }
      method gist { self.Str }
      method Str  { "$!value degrees $!unit" }
  }
  
  sub postfix:<℃> { Temperature.new: $^value, :unit<C> }
  sub postfix:<℉> { Temperature.new: $^value, :unit<F> }
  sub postfix:<K> { Temperature.new: $^value, :unit<K> }
  
  my $human := 36.6℃;
  my $book  := 451℉;
  my $sun   := 5778K;
  say $human;                # OUTPUT: «36.6 degrees C␤»
  say $human + $book + $sun; # OUTPUT: «6593.677777777778␤»
  say 123K + 456K;           # OUTPUT: «579␤»
  ```
  
  As we can see from the last two lines of the output, the type of the bridged result is not forced to be any *particular* core type. It is a [`Rat`](/type/Rat), when we instantiated `Temperature` with a [`Rat`](/type/Rat) or when conversion was involved, and it is an [`Int`](/type/Int) when we instantiated `Temperature` with an [`Int`](/type/Int).
  