txt: ## int.md
  Int
  
  Combined from primary sources listed below.
  
  # [In List](#___top "go to top of document")[§](#(List)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/List#method_Int)
  for **method Int**.
  
  ```raku
  method Int(List:D: --> Int:D)
  ```
  
  Returns the number of elements in the list (same as `.elems`).
  
  ```raku
  say (1,2,3,4,5).Int; # OUTPUT: «5␤»
  ```
  
  # [In Num](#___top "go to top of document")[§](#(Num)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Num#method_Int)
  for **method Int**.
  
  ```raku
  method Int(Num:D:)
  ```
  
  Converts the number to an [`Int`](/type/Int). [Fails](/routine/fail) with `X::Numeric::CannotConvert` if the invocant [is a `NaN`](/routine/isNaN) or `Inf`/`-Inf`. No [rounding](/routine/round) is performed.
  
  # [In enum Bool](#___top "go to top of document")[§](#(enum_Bool)_routine_Int "direct link")
  
  See primary documentation
  [in context](/type/Bool#routine_Int)
  for **routine Int**.
  
  ```raku
  multi method Int(Bool:D --> Int:D)
  ```
  
  Returns the value part of the `enum` pair.
  
  ```raku
  say False.Int;                                # OUTPUT: «0␤»
  say True.Int;                                 # OUTPUT: «1␤»
  ```
  
  # [In IntStr](#___top "go to top of document")[§](#(IntStr)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/IntStr#method_Int)
  for **method Int**.
  
  ```raku
  method Int
  ```
  
  Returns the integer value of the `IntStr`.
  
  # [In Match](#___top "go to top of document")[§](#(Match)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Match#method_Int)
  for **method Int**.
  
  ```raku
  method Int(Match:D: --> Int:D)
  ```
  
  Tries to convert stringified result of the matched text into Int.
  
  ```raku
  say ('12345' ~~ /234/).Int;       # OUTPUT: «234␤»
  say ('12345' ~~ /234/).Int.^name; # OUTPUT: «Int␤»
  # the next line produces a warning about using Nil (result of a no match) in numeric context
  say ('one-two' ~~ /234/).Int;     # OUTPUT: «0␤» # because Nil.Int returns 0
  ```
  
  # [In Str](#___top "go to top of document")[§](#(Str)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Str#method_Int)
  for **method Int**.
  
  ```raku
  method Int(Str:D: --> Int:D)
  ```
  
  Coerces the string to [`Int`](/type/Int), using the same rules as [`Str.Numeric`](/type/Str#method_Numeric).
  
  # [In role Enumeration](#___top "go to top of document")[§](#(role_Enumeration)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Enumeration#method_Int)
  for **method Int**.
  
  ```raku
  multi method Int(::?CLASS:D:)
  ```
  
  Takes a value of an enum and returns it after coercion to [`Int`](/type/Int):
  
  ```raku
  enum Numbers ( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );
  say cool.Int;           # OUTPUT: «42␤»
  say almost-pi.Int;      # OUTPUT: «3␤»
  try say sqrt-n-one.Int;
  say $!.message if $!;   # OUTPUT: «Cannot convert 0+1i to Int: imaginary part not zero␤»
  ```
  
  Note that if the value cannot be coerced to [`Int`](/type/Int), an exception will be thrown.
  
  # [In StrDistance](#___top "go to top of document")[§](#(StrDistance)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/StrDistance#method_Int)
  for **method Int**.
  
  ```raku
  multi method Int(StrDistance:D:)
  ```
  
  Returns the distance between the string before and after the transformation.
  
  # [In Map](#___top "go to top of document")[§](#(Map)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Map#method_Int)
  for **method Int**.
  
  ```raku
  method Int(Map:D: --> Int:D)
  ```
  
  Returns the number of pairs stored in the `Map` (same as `.elems`).
  
  ```raku
  my $m = Map.new('a' => 2, 'b' => 17);
  say $m.Int;                                       # OUTPUT: «2␤»
  ```
  
  # [In IO::Path](#___top "go to top of document")[§](#(IO::Path)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/IO/Path#method_Int)
  for **method Int**.
  
  ```raku
  method Int(IO::Path:D: --> Int:D)
  ```
  
  Coerces [`.basename`](/routine/basename) to [`Int`](/type/Int). [Fails](/routine/fail) with [`X::Str::Numeric`](/type/X/Str/Numeric) if base name is not numerical.
  
  # [In role Real](#___top "go to top of document")[§](#(role_Real)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Real#method_Int)
  for **method Int**.
  
  ```raku
  method Int(Real:D:)
  ```
  
  Calls the [`Bridge` method](/routine/Bridge) on the invocant and then the [`Int` method](/routine/Int) on its return value.
  
  # [In Date](#___top "go to top of document")[§](#(Date)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Date#method_Int)
  for **method Int**.
  
  ```raku
  multi method Int(Date:D: --> Int:D)
  ```
  
  Converts the invocant to [`Int`](/type/Int). The same value can be obtained with the `daycount` method.
  
  Available as of release 2023.02 of the Rakudo compiler.
  
  # [In Cool](#___top "go to top of document")[§](#(Cool)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Cool#method_Int)
  for **method Int**.
  
  ```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␤»
  ```
  
  # [In role Rational](#___top "go to top of document")[§](#(role_Rational)_method_Int "direct link")
  
  See primary documentation
  [in context](/type/Rational#method_Int)
  for **method Int**.
  
  ```raku
  method Int(Rational:D: --> Int:D)
  ```
  
  Coerces the invocant to [`Int`](/type/Int) by truncating non-whole portion of the represented number, if any. If the [denominator](/routine/denominator) is zero, will [fail](/routine/fail) with [`X::Numeric::DivideByZero`](/type/X/Numeric/DivideByZero).
  