## dist_cpan-JNTHN-Cro-HTTP-Session-Pg.md
# Cro::HTTP::Session::Pg

An implementation of Cro persistent sessions using Postgres.

## Assumptions

There are dozens of ways we might do session storage; this module handles
the case where:

* The database is being accessed using `DB::Pg`.
* You're fine with the session state being serialized and stored as a
  string/blob in the database.

If these don't meet your needs, it's best to steal the code from this
module into your own application and edit it as needed.

## Database setup

Create a table like this in the database:

```
CREATE TABLE sessions (
    id TEXT PRIMARY KEY,
    state TEXT,
    expiration TIMESTAMP
);

```

You can change the table and column names, but will then have to specify
them when constructing the session state object.

## Minimal Cro application setup

First, create a session object if you do not already have one. This is
a class that holds the session state. We'll be saving/loading its content.
For example:

```
class MySession {
    has $.user-id;

    method set-logged-in-user($!user-id --> Nil) { }

    method is-logged-in(--> Bool) { $!user-id.defined }
}

```

In the case that:

* You are using the default table/column names
* Your session object can be serialized by serializing its public attributes
  to JSON, and deserialized by passing those back to new
* You are fine with the default 60 minute session expiration time

Then the only thing needed is to construct the session storage middleware with
a database handle and a session cookie name.

```
my $session-middleware = Cro::HTTP::Session::Pg[MySession].new:
    :$db,
    :cookie-name('my_app_name_session');

```

It can then be applied as application or `route`-block level middleware.

## Tweaking the session duration

Pass a `Duration` object as the `duration` named argument:

```
my $session-middleware = Cro::HTTP::Session::Pg[MySession].new:
    :$db,
    :cookie-name('my_app_name_session'),
    :duration(Duration.new(15 #`(minutes) * 60));

```

## Tweaking the table and column names

Pass these named arguments as needed during construction:

* `sessions-table`
* `id-column`
* `state-column`
* `expiration-column`

## Controlling serialization

Instead of using the `Cro::HTTP::Session::Pg` role directly, create a
class that composes it.

```
class MySessionStore does Cro::HTTP::Session::Pg[MySession] {
    method serialize(MySession $s) {
        # Replace this with your serialization logic.
        to-json $s.Capture.hash
    }

    method deserialize($d --> MySession) {
        # Replace this with your deserialization logic.
        Session.new(|from-json($d))
    }
}

```


## dist_zef-andinus-Template-Nest-Fast.md
# Table of Contents

1. [Documentation](#org9db0562)
   1. [Options](#org84b5605)
   2. [Methods](#orgd774f96)
   3. [Example](#orgcee0c42)
      1. [Simple template hash](#org1346395)
      2. [Array of template hash](#org3cd72c2)
      3. [Array to template variable](#orgb84f6f7)
2. [News](#orgccd2661)
   1. [v0.3.0 - 2024-11-18](#org25cea46)
   2. [v0.2.8 - 2023-06-27](#orgb077a55)
   3. [v0.2.6 - 2023-05-29](#orge261c99)
   4. [v0.2.5 - 2023-05-25](#org09dca87)
   5. [v0.2.4 - 2023-05-22](#orgd4c71c5)
   6. [v0.2.3 - 2023-05-14](#orgbc37de3)
   7. [v0.2.2 - 2023-05-07](#orga686b72)
   8. [v0.2.1 - 2023-05-04](#org043a072)
   9. [v0.2.0 - 2023-05-02](#org24a7c46)
   10. [v0.1.0 - 2023-03-28](#org2302f7a)
3. [See Also](#org70013c5)

# Documentation

`Template::Nest::Fast` is a high-performance template engine module for Raku,
designed to process nested templates quickly and efficiently. This module
improves on the original `Template::Nest` module by caching the index of
positions of variables, resulting in significantly faster processing times.

For more details on `Template::Nest` visit:
<https://metacpan.org/pod/Template::Nest>

Note: This module was created by me as a proof-of-concept to benchmark against
`Template::Nest::XS`. Tom Gracey (virtual.blue) is currently sponsoring for the
development of this module. He authored `Template::Nest` originally in Perl 5.

Note: `Template::Nest::XS` is the recommended module for use in production.
Considerable effort has gone into optimising `Template::Nest::XS`, and it is now
blindingly fast. Make sure to use the latest version (v0.1.9 at the time of
writing), as some instabilities have recently been resolved.

As a pure Raku version, you may also find this module (Template::Nest::Fast)
useful for development/testing purposes - as e.g. a full stack trace can be
obtained from it (unlike the XS version which is more of a black box). There may
be other circumstances where this module is useful. However be aware it is
approx 25 times slower than the XS version.

It is not recommended to use the original pure Raku version of `Template::Nest`.
This module was a line by line rewrite of the Perl 5 module - which
unfortunately turned out to be far too slow to be practical.

## Options

* Note: The options have their hypen counterparts. For example, `comment_delims`
  is now `comment-delims`. However, for compatibility with other ::Nest
  versions, underscored options are supported on object creation.

Compatibility Progress:

```
[X] comment_delims
[X] defaults
[X] defaults_namespace_char
[X] die_on_bad_params
[ ] escape_char             - Won't be implemented
[X] fixed_indent
[X] name_label
[X] show_labels
[X] template_dir
[X] template_ext
[X] token_delims

```

* Note: `escape_char` has been replaced with `token-escape-char`.
* Note: `cache-template` option has been added and is enabled by default.
* `name-label` (default `TEMPLATE`): Represents the label used for
  identifying the template name in the hash of template variables.
* `template-dir`: IO object representing the directory where the
  templates are located.
* `cache-template` (default: `True`): If True then the whole template
  file is cached in memory, this improves performance.
* `die-on-bad-params` (default: `False`): If True, then an attempt to
  populate a template with a variable that doesn't exist (i.e. name
  not found in template file) results in an error.

  Note that it allows to leave variables undefined (i.e. name found in
  template file but not defined in template hash). Undefined variables
  are replaced with empty string. This is for compatibility with
  Template::Nest (Raku).

  You might want to keep this enabled during development & testing.
* `show-labels` (default: `False`): If True, an string is appended to
  every rendered template which is helpful in identifying which
  template the output text came from. This is useful in development
  when you have many templates.

  Example:

  ```
  <!-- BEGIN 00-simple-page -->
  <!DOCTYPE html>
  <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>Simple Page</title>
    </head>
    <body>
      <p>A fairly simple page to test the performance of Template::Nest.</p>
      <p>Simple Variable</p>
      <!-- BEGIN 01-simple-component -->
  <p>Simple Variable in Simple Component</p>
  <!-- END 01-simple-component -->
    </body>
  </html>
  <!-- END 00-simple-page -->

  ```

  Here, 'BEGIN' & 'END' blocks have been added because `show-labels`
  was set to True.

  If you're not templating HTML and still want labels, you can set
  `comment-delims`.
* `comment-delims` (default: `['<!--', '-->']`): Use this in
  conjunction with `show-labels`. Expects a 2 element array. Example,
  for templating JS you could do:

  ```
  my $nest-alt = Template::Nest::Fast.new(
      :$template-dir, :show-labels, comment-delims => ['/*', '*/']
  );

  ```

  Example output:

  ```
  /* BEGIN js-file */
  ...
  /* END js-file */

  ```

  You can set the second comment token as an empty string if the
  language you are templating does not use one. Example, for
  templating Raku you could do:

  ```
  my $nest-alt = Template::Nest::Fast.new(
      :$template-dir, :show-labels, comment-delims => ['#', '']
  );

  ```

  Example output:

  ```
  # BEGIN raku-file
  ...
  # END raku-file */

  ```
* `template-extension` (default: `html`): get/set the template
  extension. This is so you can save typing your template extension
  all the time if it's always the same. There is no reason why this
  templating system could not be used to construct any other type of
  file (or why you could not use another extension even if you were
  producing html). Example, to manipulate JavaScript files, this will
  look for `30-main.js` in `$template-dir`:

  ```
  my $nest-js = Template::Nest::Fast.new: :$template-dir, :template-extension('js');
  my %simple-page-js = %(
      TEMPLATE => '30-main',
      var => 'Simple Variable',
  );

  ```

  Or if you have an empty `template-extension`, this will look for
  `30-main.html` in `$template-dir`:

  ```
  my $nest = Template::Nest::Fast.new: :$template-dir, :template-extension('');
  my %simple-page-js = %(
      TEMPLATE => '30-main.html',
      var => 'Simple Variable',
  );

  ```
* `fixed-indent` (default: `False`): Intended to improve readability
  when inspecting nested templates. For example, consider these templates:

  wrapper.html:

  ```
  <div>
      <!--% contents %-->
  </div>

  ```

  photo.html:

  ```
  <div>
      <img src='/some-image.jpg'>
  </div>

  ```

  Output without `fixed-indent`:

  ```
  <div>
      <div>
      <img src='/some-image.jpg'>
  </div>
  </div>

  ```

  Output with `fixed-indent`:

  ```
  <div>
      <div>
          <img src='/some-image.jpg'>
      </div>
  </div>

  ```
* `token-delims` (default: `['<!--%', '%-->']`): Set the delimiters
  that define a token (to be replaced). For example, setting
  `token-delims` to `['<%', '%>']` would mean that `render` will now
  recognize and interpolate tokens in the format:

  ```
  <% variable %>

  ```
* `token-escape-char` (default: empty string): On rare occasions you
  may actually want to use the exact character string you are using
  for your token delimiters in one of your templates. For example,
  here `render` is going to consider this as a token and remove it:

  ```
  did you know we are using token delimiters <!--% and %--> in our templates?

  ```

  To include the token, escape it with `token-escape-char` set to
  (`\`):

  ```
  did you know we are using token delimiters \<!--% and %--> in our templates?

  ```

  Set it to an empty string to disable the behaviour.
* `defaults`: Provide a hash of default values that are substituted if
  template hash does not provide a value. For example, passing this
  defaults hash:

  ```
  my $nest = Template::Nest::Fast.new(
      :$template-dir,
      defaults => %(
          variable => 'Simple Variable',
          space => %(
              inside => 'A variable inside a space.'
          )
      ),
  );

  ```

  This `$nest` will first look for variable in template hash, then in
  `%defaults` hash. If no value is found then namespaced defaults are
  considered (look `defaults-namespace-char`).
* `defaults-namespace-char` (default: `.`): Say you want to namespace
  values in `%defaults` hash to differentiate parameters coming from
  template hash and chose to prefix those variables like so:

  ```
  <!--% config.title %--> - <!--% config.description %-->

  ```

  You can pass a defaults like:

  ```
  %(
      "config.title" => "Title",
      "config.description" => "Description"
  )

  ```

  However, writing `config.` repeatedly is a bit effortful, so you can
  do the following:

  ```
  %(
      config => %(
          "title" => "Title",
          "description" => "Description"
      )
  )

  ```

  Note: To disable this behaviour set `defaults-namespace-char` to an
  empty string.
* `advanced-indexing` (default: False): When enabled, `::Fast` stores the
  timestamp of template file index and if the file on disk is newer, it
  re-indexes the file. It also indexes files that are present on disk but
  weren't indexed when `::Fast` was initialized.

## Methods

* `render`: Converts a template structure to output text. See Example
  for details.

## Example

Templates:
`templates/00-simple-page.html`:

```
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Simple Page</title>
  </head>
  <body>
    <p>A fairly simple page to test the performance of Template::Nest.</p>
    <p><!--% variable %--></p>
    <!--% simple_component %-->
  </body>
</html>

```

`templates/01-simple-component.html`:

```
<p><!--% variable %--></p>

```

### Simple template hash

This is a simple example that injects a variable in a template. We use
another template as a component as well.

```
use Template::Nest::Fast;

# Create a nest object.
my $nest = Template::Nest::Fast.new( template-dir => 'templates/'.IO );

# Declare template structure.
my %simple-page = %(
    TEMPLATE => '00-simple-page',
    variable => 'Simple Variable',
    simple_component => %(
        TEMPLATE => '01-simple-component',
        variable => 'Simple Variable in Simple Component'
    )
);

# Render the page.
put $nest.render(%simple-page);

```

Output:

```
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Simple Page</title>
  </head>
  <body>
    <p>A fairly simple page to test the performance of Template::Nest.</p>
    <p>Simple Variable</p>
    <p>Simple Variable in Simple Component</p>
  </body>
</html>

```

### Array of template hash

Array of template hash can be passed to `render` too.

```
$nest.render(
    [
        %( TEMPLATE => '01-simple-component',  variable => 'This is a variable' ),
        %( TEMPLATE => '01-simple-component',  variable => 'This is another variable' )
    ]
)

```

Output:

```
<p>This is a variable</p><p>This is another variable</p>

```

### Array to template variable

Template variable can be a string, another template hash or an array too. The
array itself can contain template hash, string or nested array.

```
my %simple-page-arrays = %(
    TEMPLATE => '00-simple-page',
    variable => 'Simple Variable',
    simple_component => [
                         # Hash passed.
                         %(
                             TEMPLATE => '01-simple-component',
                             variable => 'Simple Variable in Simple Component'
                         ),
                         # Can pass string as well.
                         "<strong>Another test</strong>",
                         # Or another level of nesting.
                         [
                             %(
                                 TEMPLATE => '01-simple-component',
                                 variable => 'Simple Variable in Simple Component'
                             ),
                             "<strong>Another nested test 2</strong>"
                         ]
                     ]
);

```

Output:

```
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Simple Page</title>
  </head>
  <body>
    <p>A fairly simple page to test the performance of Template::Nest.</p>
    <p>Simple Variable</p>
    <p>Simple Variable in Simple Component</p><strong>Another test</strong><p>Simple Variable in Simple Component</p><strong>Another nested test 2</strong>
  </body>
</html>

```

# News

## v0.3.0 - 2024-11-18

* Bug Fix: Handle an escaped variable at beginning of a file. Earlier the
  program didn't treat it like an escaped variable.

## v0.2.8 - 2023-06-27

* Bug Fix: Earlier Seq was rendered as Str, now it is considered a List.

## v0.2.6 - 2023-05-29

* Improve error message for die-on-bad-params.
* Add more tests for advanced-indexing & die-on-bad-params.
* Handle template file vanishing errors.

  Handles errors where the template file has vanished.
* Fixed a bug where ::Fast does not die on non-existent template file.

  This was introduced in v0.2.5 with advanced indexing option.

## v0.2.5 - 2023-05-25

* Add advanced indexing option.

  When enabled, `::Fast` stores the timestamp of template file index and if the
  file on disk is newer, it re-indexes the file. It also indexes files that are
  present on disk but weren't indexed when `::Fast` was initialized.

## v0.2.4 - 2023-05-22

* Add support for passing array to render method.

  Template::Nest [Perl5] supports this.

  Basic Example:

  ```
  $nest.render(
      [
          %( TEMPLATE => '01-simple-component',  variable => 'This is a variable' ),
          %( TEMPLATE => '01-simple-component',  variable => 'This is another variable' )
      ]
  )

  ```

  Output:

  ```
  <p>This is a variable</p><p>This is another variable</p>

  ```
* Add examples for passing array to render method and passing array to a
  template variable.

## v0.2.3 - 2023-05-14

* Add support for underscored options.

  This makes the module close to drop-in for projects that use other Nest
  versions with support for underscored options.
* Add support for Str, nested List when parsing hash template values.

  While parsing hash template values, when we encounter a list we assume
  that all the elements will be Hash. This breaks that assumption and
  allows for the elements to be of type Hash, Str or even List.

  After this change, template hash like this will be supported:

  ```
  my %simple-page-arrays = %(
      TEMPLATE => '00-simple-page',
      variable => 'Simple Variable',
      simple_component => [
                           # Hash passed.
                           %(
                               TEMPLATE => '01-simple-component',
                               variable => 'Simple Variable in Simple Component'
                           ),
                           # Can pass string as well.
                           "<strong>Another test</strong>",
                           # Or another level of nesting.
                           [
                               %(
                                   TEMPLATE => '01-simple-component',
                                   variable => 'Simple Variable in Simple Component'
                               ),
                               "<strong>Another nested test 2</strong>"
                           ]
                       ]
  );

  ```

## v0.2.2 - 2023-05-07

* Fixed failing tests.

## v0.2.1 - 2023-05-04

* Fixed parsing bug with non-string values in template hash

  Template hash with non-string values like:

  ```
  my %template = %(
      TEMPLATE => 'simple-template',
      count => 200 # will result in failure
  );

  ```

  failed to parse prior to v0.2.1, this has been fixed in v0.2.1.
* Improve error message for invalid template hash.

## v0.2.0 - 2023-05-02

* Achieved options compatibility with Template::Nest (Raku).
* Added several options:

  * `cache-template`
  * `die-on-bad-params`
  * `show-labels`
  * `comment-delims`
  * `template-extension`
  * `fixed-indent`
  * `token-delims`
  * `token-escape-char`
  * `defaults`
  * `defaults-namespace-char`
* Note: It's not backwards compatible with Template::Nest (Raku).

## v0.1.0 - 2023-03-28

* Initial Release.

# See Also

* Template::Nest [Perl5] <https://metacpan.org/pod/Template::Nest>
* template-nest [Python] <https://pypi.org/project/template-nest/>
* Template::Nest [Raku] <https://raku.land/cpan:TOMGRACEY/Template::Nest>
* Template::Nest::XS [Raku] <https://raku.land/zef:jaffa4/Template::Nest::XS>


## dist_zef-raku-land-WebDriver.md
# WebDriver

[![pipeline](https://gitlab.com/raku-land/webdriver/badges/master/pipeline.svg)](https://gitlab.com/raku-land/webdriver/commits/master)

WebDriver is a remote control interface for web browsers.

## SYNOPSIS

```
use WebDriver;

my $wd = WebDriver.new :4444port;

# Go to Google.
$wd.get: 'https://www.google.com';

# Run a search for "raku".
$wd.find('input[name=q]').send-keys: 'raku';
$wd.find('input[value="Google Search"]').click;

# Click the first result.
$wd.find('h3').click;

# Save a screenshot of the page.
spurt 'screenshot.png', $wd.screenshot;

```

## METHODS

### Actions

#### find

```
method find(Str:D $value, Selector:D :$using = CSS) of Element

```

#### find-all

```
method find-all(Str:D $value, Selector:D :$using = CSS)

```

### Alerts

#### accept-alert

```
method accept-alert of ::?CLASS

```

Accept an alert.

#### alert-text

```
multi method alert-text              of Str
multi method alert-text(Str:D $text) of ::?CLASS

```

Get or set the text of an alert.

#### dismiss-alert

```
method dismiss-alert of ::?CLASS

```

Dismiss an alert.

### Navigation

#### back

```
method back of ::?CLASS

```

#### forward

```
method forward of ::?CLASS

```

#### get

```
method get(Str:D $url) of ::?CLASS

```

#### refresh

```
method refresh of ::?CLASS

```

## SEE ALSO

[WebDriver Spec](https://www.w3.org/TR/webdriver/)


## dist_github-jaffa4-Rakudo-Perl6-Tracer.md
# Rakudo::Perl6::Tracer

Trace Perl6 code.

Known limitations: if there is a `BEGIN`, there will not be any formatting.
Also, if classes are imported from nqp.

## Usage

```
use Rakudo::Perl6::Tracer;

my $f = Rakudo::Perl6::Tracer.new(); # create a new object
say $f.trace({},$content); #  trace the content

```

The returned program code will contain tracing statements beside the
original code.

If you run the traced code, you will see what lines were executed.

## Command line access

```
$ perl6 trace.p6 -h

$ perl6 trace.p6  <Dagrammar.p6 >traced.p6
$ perl6 trace.p6 -sl  <Dagrammar.p6 >traced.p6

```

## Example

Example of traced code, note statements are inserted by `trace.p6`:

```
sub dump_node($node)
{
 note "line  19";say "matched";
 note "line  20";if ($node<regliteral>) {
 note "line  21";say "reg $node"~$node<regliteral>;
 note "line  22";}
note "line  23";}

```

OR example trace log with -sl

```
line  1 my @Depindex;
line  2 my @Depthis;
line  3 my @Depon;
line  4 my @Depend;
line  5 my @Bot;
line  7 my $debug = False;
line  215 my %h;
line  216 my %g;
line  217 %h<itemid> = 1;
line  218 %g<itemid> = 2;
line  219 %h<name>   = '1';
line  220 %g<name>   = '2';
line  222 my %j  = ( "itemid", 3, "name", 3 );
line  223 my %j4 = ( "itemid", 4, "name", 4 );

```


## dist_github-lestrrat-p6-Apache-LogFormat.md
[![Build Status](https://travis-ci.org/lestrrat/p6-Apache-LogFormat.svg?branch=master)](https://travis-ci.org/lestrrat/p6-Apache-LogFormat)

# NAME

Apache::LogFormat - Provide Apache-Style Log Generators

# SYNOPSIS

```
# Use a predefined log format to generate string for logging
use Apache::LogFormat;
my $fmt = Apache::LogFormat.combined;
my $line = $fmt.format(%env, @res, $length, $reqtime, $time);
$*ERR.print($line);

# Compile your own log formatter
use Apache::LogFormat::Compiler;
my $c = Apache::LogFormat::Compiler.new;
my $fmt = $c.compile(' ... pattern ... ');
my $line = $fmt.format(%env, @res, $length, $reqtime, $time);
$*ERR.print($line);

```

# DESCRIPTION

Apache::LogFormat provides Apache-style log generators.

# PRE DEFINED FORMATTERS

## common(): $fmt:Apache::LogFormat::Formatter

Creates a new Apache::LogFormat::Formatter that generates log lines in the following format:

```
%h %l %u %t "%r" %>s %b

```

## combined(): $fmt:Apache::LogFormat::Formatter

Creates a new Apache::LogFormat::Formatter that generates log lines in the following format:

```
%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"

```

# AUTHOR

Daisuke Maki [lestrrat@gmail.com](mailto:lestrrat@gmail.com)

# COPYRIGHT AND LICENSE

Copyright 2015 Daisuke Maki

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.


## dist_zef-lizmat-Set-Equality.md
[![Actions Status](https://github.com/lizmat/Set-Equality/workflows/test/badge.svg)](https://github.com/lizmat/Set-Equality/actions)

# NAME

Set::Equality - Implement (==) for older Raku versions

# SYNOPSIS

```
use Set::Equality;

say (1,2,3) (==) (3,1,2);  # True

```

# DESCRIPTION

The `Set::Equality` module implements the `(==)` operator (and its unicode version `≡`, and its counterpart `≢`) for versions of Raku **before** the 2020.06 Rakudo compiler release. Its implementation and tests are identical to the ones from Rakudo 2020.06 and later.

On versions of Rakudo that already implement the `(==)` operator and its friends, loading this module is basically a no-op.

The `(==)` operator conceptually coerces its parameters to `Set`s for non-`QuantHash` types. So:

```
(1,2,3) (==) (3,1,2)

```

is conceptually the same as:

```
(1,2,3).Set eqv (3,1,2).Set

```

It will however actually do as little actual coercion as possible to provide the `True` or `False` it is to return. For example:

```
<foo bar baz> (==) %hash

```

will return `True` if there are 3 keys in the hash, and they are `foo`, `bar` and `baz`, and each of these keys holds a truthy value.

# AUTHOR

Elizabeth Mattijsen [liz@raku.rocks](mailto:liz@raku.rocks)

Source can be located at: <https://github.com/lizmat/Set-Equality> . Comments and Pull Requests are welcome.

If you like this module, or what I’m doing more generally, committing to a [small sponsorship](https://github.com/sponsors/lizmat/) would mean a great deal to me!

# COPYRIGHT AND LICENSE

Copyright 2020, 2021, 2024 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.


## dist_cpan-FOOIST-Readline.md
# Readline

##### *Note: This README will soon be updated based on new development priorities*

Readline provides a Perl 6 interface to libreadline.

XXX This will probably be a frontend to Readline::Gnu when that's factored out.
XXX For the moment keep all the code here in the Readline module.

# Installation

Please make sure that libreadline is installed beforehand, the tests will fail otherwise. If libreadline is installed but the tests still fail, please note that the Perl 6 package searches a given set of directories for libreadline.{so,dynlib}.\* files, otherwise it defaults to v7. If your libreadline installation isn't on any of these paths, or requires non-standard setup, please file an issue.

For those of you on Linux Debian and Linux-alike systems, you should be able to get the latest version with this CLI invocation:

```
	sudo apt-get install libreadline7

```

(I'd prefer to use LibraryCheck, but it fails inside the 'is native()' method call.)

On Macs, use Hombrew to install readline. If you installed Rakudo-Star with homebrew after Sept. 1 it should already be there.

If not you can install just Readline

```
    brew install readline

```

or update your rakudo-star install.

```
    brew upgrade rakudo-star

```

* Using zef (a module management tool bundled with Rakudo Star):

```
    zef update && zef install Readline

```

Or alternatively installing it from a checkout of this repo with zef:

```
    zef install .

```

## Usage

See the `examples/` directory in this project.

## Testing

To run tests:

```
    prove -e perl6

```

## Author

Jeffrey Goff, DrForr on #perl6, <https://github.com/drforr/>
(Recently taken over by Daniel Lathrop (fooist), <https://github.com/fooist/>

## License

Artistic License 2.0


## cool.md
## Chunk 1 of 3
class Cool

Object that can be treated as both a string and number

```raku
class Cool is Any { }
```

`Cool`, also known as the **C**onvenient **OO** **L**oop, is a base class employed by a number of built-in classes whose instances can be meaningfully coerced to a string and a number. For example, an [`Array`](/type/Array) can be used in mathematical operations, where its numerical representation is the number of elements it contains. At the same time, it can be concatenated to a string, where its stringy representation is all of its elements [joined](/routine/join) by a space. Because [`Array`](/type/Array) is `Cool`, the appropriate coercion happens automatically.

Methods in `Cool` coerce the invocant to a more specific type, and then call the same method on that type. For example both [`Int`](/type/Int) and [`Str`](/type/Str) inherit from `Cool`, and calling method `substr` on an [`Int`](/type/Int) converts the integer to [`Str`](/type/Str) first.

```raku
123.substr(1, 1);   # '2', same as 123.Str.substr(1, 1)
```

Several built-in types inherit from `Cool`. See the [Type Graph](#typegraphrelations) below for a snapshot.

The following table summarizes the methods that `Cool` provides, and what type they coerce to:

| method | coercion type |
| --- | --- |
| abs | Numeric |
| conj | Numeric |
| sqrt | Numeric |
| sign | Real |
| rand | Numeric |
| sin | Numeric |
| asin | Numeric |
| cos | Numeric |
| acos | Numeric |
| tan | Numeric |
| tanh | Numeric |
| atan | Numeric |
| atan2 | Numeric |
| atanh | Numeric |
| sec | Numeric |
| asec | Numeric |
| cosec | Numeric |
| acosec | Numeric |
| cotan | Numeric |
| cotanh | Numeric |
| acotan | Numeric |
| sinh | Numeric |
| asinh | Numeric |
| cosh | Numeric |
| acosh | Numeric |
| sech | Numeric |
| asech | Numeric |
| cosech | Numeric |
| acosech | Numeric |
| acotanh | Numeric |
| cis | Numeric |
| log | Numeric |
| exp | Numeric |
| roots | Numeric |
| log10 | Numeric |
| log2 | Numeric |
| unpolar | Numeric |
| round | Numeric |
| floor | Numeric |
| ceiling | Numeric |
| truncate | Numeric |
| chr | Int |
| ord | Str |
| chars | Str |
| fmt | Str |
| uniname | Str |
| uninames | Seq |
| unival | Str |
| univals | Str |
| uniprop | Str |
| unimatch | Str |
| uc | Str |
| lc | Str |
| fc | Str |
| tc | Str |
| tclc | Str |
| flip | Str |
| trans | Str |
| contains | Str |
| index | Str |
| rindex | Str |
| ords | Str |
| split | Str |
| match | Str |
| comb | Str |
| subst | Str |
| sprintf | Str |
| printf | Str |
| samecase | Str |
| trim | Str |
| trim-leading | Str |
| trim-trailing | Str |
| EVAL | Str |
| chomp | Str |
| chop | Str |
| codes | Str |
| Complex | Numeric |
| FatRat | Numeric |
| Int | Numeric |
| Num | Numeric |
| Rat | Numeric |
| Real | Numeric |
| UInt | Numeric |

# [Methods](#class_Cool "go to top of document")[§](#Methods "direct link")

## [routine abs](#class_Cool "go to top of document")[§](#routine_abs "direct link")

```raku
sub abs(Numeric() $x)
method abs()
```

Coerces the invocant (or in the sub form, the argument) to [`Numeric`](/type/Numeric) and returns the absolute value (that is, a non-negative number).

```raku
say (-2).abs;       # OUTPUT: «2␤»
say abs "6+8i";     # OUTPUT: «10␤»
```

## [method conj](#class_Cool "go to top of document")[§](#method_conj "direct link")

```raku
method conj()
```

Coerces the invocant to [`Numeric`](/type/Numeric) and returns the [`Complex`](/type/Complex) conjugate (that is, the number with the sign of the imaginary part negated).

```raku
say (1+2i).conj;        # OUTPUT: «1-2i␤»
```

## [method EVAL](#class_Cool "go to top of document")[§](#method_EVAL "direct link")

```raku
method EVAL(*%_)

```

It calls the [subroutine form](/type/independent-routines#routine_EVAL) with the invocant as the first argument, `$code`, passing along named args, if any.

## [routine sqrt](#class_Cool "go to top of document")[§](#routine_sqrt "direct link")

```raku
sub sqrt(Numeric(Cool) $x)
method sqrt()
```

Coerces the invocant to [`Numeric`](/type/Numeric) (or in the sub form, the argument) and returns the square root, that is, a number that, when multiplied with itself, produces the original number.

```raku
say 4.sqrt;             # OUTPUT: «2␤»
say sqrt(2);            # OUTPUT: «1.4142135623731␤»
```

Returns `NaN` for negative arguments. As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a [`Complex`](/type/Complex) value for negative arguments.

```raku
say sqrt(-1);           # OUTPUT: «0+1i␤»
```

## [method sign](#class_Cool "go to top of document")[§](#method_sign "direct link")

```raku
method sign()
```

Coerces the invocant to [`Real`](/type/Real) and returns its sign, that is, 0 if the number is 0, 1 for positive and -1 for negative values.

```raku
say 6.sign;             # OUTPUT: «1␤»
say (-6).sign;          # OUTPUT: «-1␤»
say "0".sign;           # OUTPUT: «0␤»
```

## [method rand](#class_Cool "go to top of document")[§](#method_rand "direct link")

```raku
method rand()
```

Coerces the invocant to [`Num`](/type/Num) and returns a pseudo-random value between zero and the number.

```raku
say 1e5.rand;           # OUTPUT: «33128.495184283␤»
```

## [routine sin](#class_Cool "go to top of document")[§](#routine_sin "direct link")

```raku
sub sin(Numeric(Cool))
method sin()
```

Coerces the invocant (or in the sub form, the argument) to [`Numeric`](/type/Numeric), interprets it as radians, returns its [sine](https://en.wikipedia.org/wiki/Sine).

```raku
say sin(0);             # OUTPUT: «0␤»
say sin(pi/4);          # OUTPUT: «0.707106781186547␤»
say sin(pi/2);          # OUTPUT: «1␤»
```

Note that Raku is no computer algebra system, so `sin(pi)` typically does not produce an exact 0, but rather a very small [`Num`](/type/Num).

## [routine asin](#class_Cool "go to top of document")[§](#routine_asin "direct link")

```raku
sub asin(Numeric(Cool))
method asin()
```

Coerces the invocant (or in the sub form, the argument) to [`Numeric`](/type/Numeric), and returns its [arc-sine](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) in radians.

```raku
say 0.1.asin;               # OUTPUT: «0.10016742116156␤»
say asin(0.1);              # OUTPUT: «0.10016742116156␤»
```

## [routine cos](#class_Cool "go to top of document")[§](#routine_cos "direct link")

```raku
sub cos(Numeric(Cool))
method cos()
```

Coerces the invocant (or in sub form, the argument) to [`Numeric`](/type/Numeric), interprets it as radians, returns its [cosine](https://en.wikipedia.org/wiki/Cosine).

```raku
say 0.cos;                  # OUTPUT: «1␤»
say pi.cos;                 # OUTPUT: «-1␤»
say cos(pi/2);              # OUTPUT: «6.12323399573677e-17␤»
```

## [routine acos](#class_Cool "go to top of document")[§](#routine_acos "direct link")

```raku
sub acos(Numeric(Cool))
method acos()
```

Coerces the invocant (or in sub form, the argument) to [`Numeric`](/type/Numeric), and returns its [arc-cosine](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) in radians.

```raku
say 1.acos;                 # OUTPUT: «0␤»
say acos(-1);               # OUTPUT: «3.14159265358979␤»
```

## [routine tan](#class_Cool "go to top of document")[§](#routine_tan "direct link")

```raku
sub tan(Numeric(Cool))
method tan()
```

Coerces the invocant (or in sub form, the argument) to [`Numeric`](/type/Numeric), interprets it as radians, returns its [tangent](https://en.wikipedia.org/wiki/Tangent).

```raku
say tan(3);                 # OUTPUT: «-0.142546543074278␤»
say 3.tan;                  # OUTPUT: «-0.142546543074278␤»
```

## [routine atan](#class_Cool "go to top of document")[§](#routine_atan "direct link")

```raku
sub atan(Numeric(Cool))
method atan()
```

Coerces the invocant (or in sub form, the argument) to [`Numeric`](/type/Numeric), and returns its [arc-tangent](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) in radians.

```raku
say atan(3);                # OUTPUT: «1.24904577239825␤»
say 3.atan;                 # OUTPUT: «1.24904577239825␤»
```

## [routine atan2](#class_Cool "go to top of document")[§](#routine_atan2 "direct link")

```raku
sub atan2($y, $x = 1e0)
method atan2($x = 1e0)
```

The sub should usually be written with two arguments for clarity as it is seen in other languages and in mathematical texts, but the single-argument form is available; its result will always match that of [atan](/routine/atan).

```raku
say atan2 3, 1;             # OUTPUT: «1.2490457723982544␤»
say atan2 3;                # OUTPUT: «1.2490457723982544␤»
say atan2 ⅔, ⅓;             # OUTPUT: «1.1071487177940904␤»
```

The method coerces self and its single argument to [`Numeric`](/type/Numeric), using them to compute the two-argument [arc-tangent](https://en.wikipedia.org/wiki/Atan2) in radians.

```raku
say 3.atan2;                # OUTPUT: «1.24904577239825␤»
say ⅔.atan2(⅓);             # OUTPUT: «1.1071487177940904␤»
```

The $x argument in either the method or the sub defaults to 1 so, in both single-argument cases, the function will return the angle θ in radians between the x-axis and a vector that goes from the origin to the point (3, 1).

## [routine sec](#class_Cool "go to top of document")[§](#routine_sec "direct link")

```raku
sub sec(Numeric(Cool))
method sec()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), interprets it as radians, returns its [secant](https://en.wikipedia.org/wiki/Trigonometric_functions#Reciprocal_functions), that is, the reciprocal of its cosine.

```raku
say 45.sec;                 # OUTPUT: «1.90359440740442␤»
say sec(45);                # OUTPUT: «1.90359440740442␤»
```

## [routine asec](#class_Cool "go to top of document")[§](#routine_asec "direct link")

```raku
sub asec(Numeric(Cool))
method asec()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [arc-secant](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) in radians.

```raku
say 1.asec;                 # OUTPUT: «0␤»
say sqrt(2).asec;           # OUTPUT: «0.785398163397448␤»
```

## [routine cosec](#class_Cool "go to top of document")[§](#routine_cosec "direct link")

```raku
sub cosec(Numeric(Cool))
method cosec()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), interprets it as radians, returns its [cosecant](https://en.wikipedia.org/wiki/Trigonometric_functions#Reciprocal_functions), that is, the reciprocal of its sine.

```raku
say 0.45.cosec;             # OUTPUT: «2.29903273150897␤»
say cosec(0.45);            # OUTPUT: «2.29903273150897␤»
```

## [routine acosec](#class_Cool "go to top of document")[§](#routine_acosec "direct link")

```raku
sub acosec(Numeric(Cool))
method acosec()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [arc-cosecant](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) in radians.

```raku
say 45.acosec;              # OUTPUT: «0.0222240516182672␤»
say acosec(45)              # OUTPUT: «0.0222240516182672␤»
```

## [routine cotan](#class_Cool "go to top of document")[§](#routine_cotan "direct link")

```raku
sub cotan(Numeric(Cool))
method cotan()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), interprets it as radians, returns its [cotangent](https://en.wikipedia.org/wiki/Trigonometric_functions#Reciprocal_functions), that is, the reciprocal of its tangent.

```raku
say 45.cotan;               # OUTPUT: «0.617369623783555␤»
say cotan(45);              # OUTPUT: «0.617369623783555␤»
```

## [routine acotan](#class_Cool "go to top of document")[§](#routine_acotan "direct link")

```raku
sub acotan(Numeric(Cool))
method acotan()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [arc-cotangent](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) in radians.

```raku
say 45.acotan;              # OUTPUT: «0.0222185653267191␤»
say acotan(45)              # OUTPUT: «0.0222185653267191␤»
```

## [routine sinh](#class_Cool "go to top of document")[§](#routine_sinh "direct link")

```raku
sub sinh(Numeric(Cool))
method sinh()
```

Coerces the invocant (or in method form, its argument) to [`Numeric`](/type/Numeric), and returns its [Sine hyperbolicus](https://en.wikipedia.org/wiki/Hyperbolic_function).

```raku
say 1.sinh;                 # OUTPUT: «1.1752011936438␤»
say sinh(1);                # OUTPUT: «1.1752011936438␤»
```

## [routine asinh](#class_Cool "go to top of document")[§](#routine_asinh "direct link")

```raku
sub asinh(Numeric(Cool))
method asinh()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Inverse Sine hyperbolicus](https://en.wikipedia.org/wiki/Inverse_hyperbolic_function).

```raku
say 1.asinh;                # OUTPUT: «0.881373587019543␤»
say asinh(1);               # OUTPUT: «0.881373587019543␤»
```

## [routine cosh](#class_Cool "go to top of document")[§](#routine_cosh "direct link")

```raku
sub cosh(Numeric(Cool))
method cosh()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Cosine hyperbolicus](https://en.wikipedia.org/wiki/Hyperbolic_function).

```raku
say cosh(0.5);              # OUTPUT: «1.12762596520638␤»
```

## [routine acosh](#class_Cool "go to top of document")[§](#routine_acosh "direct link")

```raku
sub acosh(Numeric(Cool))
method acosh()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Inverse Cosine hyperbolicus](https://en.wikipedia.org/wiki/Inverse_hyperbolic_function).

```raku
say acosh(45);              # OUTPUT: «4.4996861906715␤»
```

## [routine tanh](#class_Cool "go to top of document")[§](#routine_tanh "direct link")

```raku
sub tanh(Numeric(Cool))
method tanh()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), interprets it as radians and returns its [Tangent hyperbolicus](https://en.wikipedia.org/wiki/Hyperbolic_function).

```raku
say tanh(0.5);              # OUTPUT: «0.46211715726001␤»
say tanh(atanh(0.5));       # OUTPUT: «0.5␤»
```

## [routine atanh](#class_Cool "go to top of document")[§](#routine_atanh "direct link")

```raku
sub atanh(Numeric(Cool))
method atanh()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Inverse tangent hyperbolicus](https://en.wikipedia.org/wiki/Inverse_hyperbolic_function).

```raku
say atanh(0.5);             # OUTPUT: «0.549306144334055␤»
```

## [routine sech](#class_Cool "go to top of document")[§](#routine_sech "direct link")

```raku
sub sech(Numeric(Cool))
method sech()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Secant hyperbolicus](https://en.wikipedia.org/wiki/Hyperbolic_function).

```raku
say 0.sech;                 # OUTPUT: «1␤»
```

## [routine asech](#class_Cool "go to top of document")[§](#routine_asech "direct link")

```raku
sub asech(Numeric(Cool))
method asech()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Inverse hyperbolic secant](https://en.wikipedia.org/wiki/Hyperbolic_function).

```raku
say 0.8.asech;              # OUTPUT: «0.693147180559945␤»
```

## [routine cosech](#class_Cool "go to top of document")[§](#routine_cosech "direct link")

```raku
sub cosech(Numeric(Cool))
method cosech()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Hyperbolic cosecant](https://en.wikipedia.org/wiki/Hyperbolic_function).

```raku
say cosech(pi/2);           # OUTPUT: «0.434537208094696␤»
```

## [routine acosech](#class_Cool "go to top of document")[§](#routine_acosech "direct link")

```raku
sub acosech(Numeric(Cool))
method acosech()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Inverse hyperbolic cosecant](https://en.wikipedia.org/wiki/Inverse_hyperbolic_function).

```raku
say acosech(4.5);           # OUTPUT: «0.220432720979802␤»
```

## [routine cotanh](#class_Cool "go to top of document")[§](#routine_cotanh "direct link")

```raku
sub cotanh(Numeric(Cool))
method cotanh()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Hyperbolic cotangent](https://en.wikipedia.org/wiki/Hyperbolic_function).

```raku
say cotanh(pi);             # OUTPUT: «1.00374187319732␤»
```

## [routine acotanh](#class_Cool "go to top of document")[§](#routine_acotanh "direct link")

```raku
sub acotanh(Numeric(Cool))
method acotanh()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns its [Inverse hyperbolic cotangent](https://en.wikipedia.org/wiki/Inverse_hyperbolic_function).

```raku
say acotanh(2.5);           # OUTPUT: «0.423648930193602␤»
```

## [routine cis](#class_Cool "go to top of document")[§](#routine_cis "direct link")

```raku
sub cis(Numeric(Cool))
method cis()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and returns [cos(argument) + i\*sin(argument)](https://en.wikipedia.org/wiki/Cis_%28mathematics%29).

```raku
say cis(pi/4);              # OUTPUT: «0.707106781186548+0.707106781186547i␤»
```

## [routine log](#class_Cool "go to top of document")[§](#routine_log "direct link")

```raku
multi        log(Numeric(Cool) $number, Numeric(Cool) $base?)
multi method log(Cool:D: Cool:D $base?)
```

Coerces the arguments (including the invocant in the method form) to [`Numeric`](/type/Numeric), and returns its [Logarithm](https://en.wikipedia.org/wiki/Logarithm) to base `$base`, or to base `e` (Euler's Number) if no base was supplied ([Natural logarithm](https://en.wikipedia.org/wiki/Natural_logarithm)). Throws an exception if `$base` is `1`.

```raku
say (e*e).log;              # OUTPUT: «2␤»
```

Returns `NaN` for negative arguments. As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a [`Complex`](/type/Complex) value for negative arguments.

## [routine log10](#class_Cool "go to top of document")[§](#routine_log10 "direct link")

```raku
multi method log10()
multi        log10(Numeric $x)
multi        log10(Cool    $x)
```

Coerces the invocant (or in the sub form, the argument) to [`Numeric`](/type/Numeric) (or uses it directly if it's already in that form), and returns its [Logarithm](https://en.wikipedia.org/wiki/Logarithm) in base 10, that is, a number that approximately produces the original number when 10 is raised to its power. Returns `-Inf` for `0`.

```raku
say log10(1001);            # OUTPUT: «3.00043407747932␤»
```

Returns `NaN` for negative arguments. As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a [`Complex`](/type/Complex) value for negative arguments.

## [routine log2](#class_Cool "go to top of document")[§](#routine_log2 "direct link")

```raku
multi method log2()
multi        log2(Numeric $x)
multi        log2(Cool    $x)
```

Coerces the invocant to [`Numeric`](/type/Numeric), and returns its [Logarithm](https://en.wikipedia.org/wiki/Logarithm) in base 2, that is, a number that approximately (due to computer precision limitations) produces the original number when 2 is raised to its power. Returns `-Inf` for `0`.

```raku
say log2(5);            # OUTPUT: «2.321928094887362␤»
say "4".log2;           # OUTPUT: «2␤»
say 4.log2;             # OUTPUT: «2␤»
```

Returns `NaN` for negative arguments. As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a [`Complex`](/type/Complex) value for negative arguments.

## [routine exp](#class_Cool "go to top of document")[§](#routine_exp "direct link")

```raku
multi        exp(Cool:D $pow, Cool:D $base?)
multi method exp(Cool:D: Cool:D $base?)
```

Coerces the arguments (including the invocant in the method from) to [`Numeric`](/type/Numeric), and returns `$base` raised to the power of the first number. If no `$base` is supplied, `e` (Euler's Number) is used.

```raku
say 0.exp;      # OUTPUT: «1␤»
say 1.exp;      # OUTPUT: «2.71828182845905␤»
say 10.exp;     # OUTPUT: «22026.4657948067␤»
```

## [method unpolar](#class_Cool "go to top of document")[§](#method_unpolar "direct link")

```raku
method unpolar(Numeric(Cool))
```

Coerces the arguments (including the invocant in the method form) to [`Numeric`](/type/Numeric), and returns a complex number from the given polar coordinates. The invocant (or the first argument in sub form) is the magnitude while the argument (i.e. the second argument in sub form) is the angle. The angle is assumed to be in radians.

```raku
say sqrt(2).unpolar(pi/4);      # OUTPUT: «1+1i␤»
```

## [routine round](#class_Cool "go to top of document")[§](#routine_round "direct link")

```raku
multi        round(Numeric(Cool), $scale = 1)
multi method round(Cool:D: $scale = 1)
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and rounds it to the unit of `$scale`. If `$scale` is 1, rounds to the nearest integer; an arbitrary scale will result in the closest multiple of that number.

```raku
say 1.7.round;          # OUTPUT: «2␤»
say 1.07.round(0.1);    # OUTPUT: «1.1␤»
say 21.round(10);       # OUTPUT: «20␤»
say round(1000, 23.01)  # OUTPUT: «989.43␤»
```

Always rounds **up** if the number is at mid-point:

```raku
say (−.5 ).round;       # OUTPUT: «0␤»
say ( .5 ).round;       # OUTPUT: «1␤»
say (−.55).round(.1);   # OUTPUT: «-0.5␤»
say ( .55).round(.1);   # OUTPUT: «0.6␤»
```

**Pay attention** to types when using this method, as ending up with the wrong type may affect the precision you seek to achieve. For [`Real`](/type/Real) types, the type of the result is the type of the argument ([`Complex`](/type/Complex) argument gets coerced to [`Real`](/type/Real), ending up a [`Num`](/type/Num)). If rounding a [`Complex`](/type/Complex), the result is [`Complex`](/type/Complex) as well, regardless of the type of the argument.

```raku
9930972392403501.round(1)      .raku.say; # OUTPUT: «9930972392403501␤»
9930972392403501.round(1e0)    .raku.say; # OUTPUT: «9.9309723924035e+15␤»
9930972392403501.round(1e0).Int.raku.say; # OUTPUT: «9930972392403500␤»
```

## [routine floor](#class_Cool "go to top of document")[§](#routine_floor "direct link")

```raku
multi        floor(Numeric(Cool))
multi method floor
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and rounds it downwards to the nearest integer.

```raku
say "1.99".floor;       # OUTPUT: «1␤»
say "-1.9".floor;       # OUTPUT: «-2␤»
say 0.floor;            # OUTPUT: «0␤»
```

## [method fmt](#class_Cool "go to top of document")[§](#method_fmt "direct link")

```raku
method fmt($format = '%s')
```

Uses `$format` to return a formatted representation of the invocant; equivalent to calling [sprintf](/routine/sprintf) with `$format` as format and the invocant as the second argument. The `$format` will be coerced to [`Stringy`](/type/Stringy) and defaults to `'%s'`.

For more information about formats strings, see [sprintf](/routine/sprintf).

```raku
say 11.fmt('This Int equals %03d');         # OUTPUT: «This Int equals 011␤»
say '16'.fmt('Hexadecimal %x');             # OUTPUT: «Hexadecimal 10␤»
```

## [routine ceiling](#class_Cool "go to top of document")[§](#routine_ceiling "direct link")

```raku
multi        ceiling(Numeric(Cool))
multi method ceiling
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and rounds it upwards to the nearest integer.

```raku
say "1".ceiling;        # OUTPUT: «1␤»
say "-0.9".ceiling;     # OUTPUT: «0␤»
say "42.1".ceiling;     # OUTPUT: «43␤»
```

## [routine truncate](#class_Cool "go to top of document")[§](#routine_truncate "direct link")

```raku
multi        truncate(Numeric(Cool))
multi method truncate()
```

Coerces the invocant (or in sub form, its argument) to [`Numeric`](/type/Numeric), and rounds it towards zero.

```raku
say 1.2.truncate;       # OUTPUT: «1␤»
say truncate -1.2;      # OUTPUT: «-1␤»
```

## [routine ord](#class_Cool "go to top of document")[§](#routine_ord "direct link")

```raku
sub ord(Str(Cool))
method ord()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns the [Unicode code point](https://en.wikipedia.org/wiki/Code_point) number of the first code point.

```raku
say 'a'.ord;            # OUTPUT: «97␤»
```

The inverse operation is [chr](/routine/chr).


## cool.md
## Chunk 2 of 3
Mnemonic: returns an ordinal number

## [method path](#class_Cool "go to top of document")[§](#method_path "direct link")

```raku
method path(Cool:D: --> IO::Path:D)
```

**DEPRECATED**. *It's been deprecated as of the 6.d version. Will be removed in the next ones.*

Stringifies the invocant and converts it to [`IO::Path`](/type/IO/Path) object. Use the [`.IO method`](/routine/IO) instead.

## [routine chr](#class_Cool "go to top of document")[§](#routine_chr "direct link")

```raku
sub chr(Int(Cool))
method chr()
```

Coerces the invocant (or in sub form, its argument) to [`Int`](/type/Int), interprets it as a [Unicode code points](https://en.wikipedia.org/wiki/Code_point), and returns a [`Str`](/type/Str) made of that code point.

```raku
say '65'.chr;       # OUTPUT: «A␤»
```

The inverse operation is [ord](/routine/ord).

Mnemonic: turns an integer into a *char*acter.

## [routine chars](#class_Cool "go to top of document")[§](#routine_chars "direct link")

```raku
multi  chars(Cool $x)
multi  chars(Str:D $x)
multi  chars(str $x --> int)
method chars(--> Int:D)
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns the number of characters in the string. Please note that on the JVM, you currently get codepoints instead of graphemes.

```raku
say 'møp'.chars;    # OUTPUT: «3␤»
say 'ã̷̠̬̊'.chars;     # OUTPUT: «1␤»
say '👨👩👧👦🏿'.chars;    # OUTPUT: «1␤»
```

If the string is native, the number of chars will be also returned as a native `int`.

Graphemes are user visible characters. That is, this is what the user thinks of as a “character”.

Graphemes can contain more than one codepoint. Typically the number of graphemes and codepoints differs when `Prepend` or `Extend` characters are involved (also known as [Combining characters](https://en.wikipedia.org/wiki/Combining_character)), but there are many other cases when this may happen. Another example is `\c[ZWJ]` ([Zero-width joiner](https://en.wikipedia.org/wiki/Zero-width_joiner)).

You can check `Grapheme_Cluster_Break` property of a character in order to see how it is going to behave:

```raku
say ‘ã̷̠̬̊’.uniprops(‘Grapheme_Cluster_Break’); # OUTPUT: «(Other Extend Extend Extend Extend)␤»
say ‘👨👩👧👦🏿’.uniprops(‘Grapheme_Cluster_Break’); # OUTPUT: «(E_Base_GAZ ZWJ E_Base_GAZ ZWJ E_Base_GAZ ZWJ E_Base_GAZ E_Modifier)␤»
```

You can read more about graphemes in the [Unicode Standard](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries), which Raku tightly follows, using a method called [NFG, normal form graphemes](/language/glossary#NFG) for efficiently representing them.

## [routine codes](#class_Cool "go to top of document")[§](#routine_codes "direct link")

```raku
sub codes(Str(Cool))
method codes()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns the number of [Unicode code points](https://en.wikipedia.org/wiki/Code_point).

```raku
say 'møp'.codes;    # OUTPUT: «3␤»
```

The same result will be obtained with

```raku
say +'møp'.ords;    # OUTPUT: «3␤»
```

[ords](/routine/ords) first obtains the actual codepoints, so there might be a difference in speed.

## [routine flip](#class_Cool "go to top of document")[§](#routine_flip "direct link")

```raku
sub flip(Cool $s --> Str:D)
method flip()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns a reversed version.

```raku
say 421.flip;       # OUTPUT: «124␤»
```

## [routine trim](#class_Cool "go to top of document")[§](#routine_trim "direct link")

```raku
sub trim(Str(Cool))
method trim()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns the string with both leading and trailing whitespace stripped.

```raku
my $stripped = '  abc '.trim;
say "<$stripped>";          # OUTPUT: «<abc>␤»
```

## [routine trim-leading](#class_Cool "go to top of document")[§](#routine_trim-leading "direct link")

```raku
sub trim-leading(Str(Cool))
method trim-leading()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns the string with leading whitespace stripped.

```raku
my $stripped = '  abc '.trim-leading;
say "<$stripped>";          # OUTPUT: «<abc >␤»
```

## [routine trim-trailing](#class_Cool "go to top of document")[§](#routine_trim-trailing "direct link")

```raku
sub trim-trailing(Str(Cool))
method trim-trailing()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns the string with trailing whitespace stripped.

```raku
my $stripped = '  abc '.trim-trailing;
say "<$stripped>";          # OUTPUT: «<  abc>␤»
```

## [routine lc](#class_Cool "go to top of document")[§](#routine_lc "direct link")

```raku
sub lc(Str(Cool))
method lc()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns it case-folded to lowercase.

```raku
say "ABC".lc;       # OUTPUT: «abc␤»
```

## [routine uc](#class_Cool "go to top of document")[§](#routine_uc "direct link")

```raku
sub uc(Str(Cool))
method uc()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns it case-folded to uppercase (capital letters).

```raku
say "Abc".uc;       # OUTPUT: «ABC␤»
```

## [routine fc](#class_Cool "go to top of document")[§](#routine_fc "direct link")

```raku
sub fc(Str(Cool))
method fc()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns the result a Unicode "case fold" operation suitable for doing caseless string comparisons. (In general, the returned string is unlikely to be useful for any purpose other than comparison.)

```raku
say "groß".fc;       # OUTPUT: «gross␤»
```

## [routine tc](#class_Cool "go to top of document")[§](#routine_tc "direct link")

```raku
sub tc(Str(Cool))
method tc()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns it with the first letter case-folded to titlecase (or where not available, uppercase).

```raku
say "abC".tc;       # OUTPUT: «AbC␤»
```

## [routine tclc](#class_Cool "go to top of document")[§](#routine_tclc "direct link")

```raku
sub tclc(Str(Cool))
method tclc()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns it with the first letter case-folded to titlecase (or where not available, uppercase), and the rest of the string case-folded to lowercase.

```raku
say 'abC'.tclc;     # OUTPUT: «Abc␤»
```

## [routine wordcase](#class_Cool "go to top of document")[§](#routine_wordcase "direct link")

```raku
sub wordcase(Str(Cool) $input, :&filter = &tclc, Mu :$where = True)
method wordcase(:&filter = &tclc, Mu :$where = True)
```

Coerces the invocant (or in sub form, the first argument) to [`Str`](/type/Str), and filters each word that smartmatches against `$where` through the `&filter`. With the default filter (first character to uppercase, rest to lowercase) and matcher (which accepts everything), this titlecases each word:

```raku
say "raku programming".wordcase;        # OUTPUT: «Raku Programming␤»
```

With a matcher:

```raku
say "have fun working on raku".wordcase(:where({ .chars > 3 }));
                                        # Have fun Working on Raku
```

With a customer filter too:

```raku
say "have fun working on raku".wordcase(:filter(&uc), :where({ .chars > 3 }));
                                        # HAVE fun WORKING on RAKU
```

## [routine samecase](#class_Cool "go to top of document")[§](#routine_samecase "direct link")

```raku
sub samecase(Cool $string, Cool $pattern)
method samecase(Cool:D: Cool $pattern)
```

Coerces the invocant (or in sub form, the first argument) to [`Str`](/type/Str), and calls [`Str.samecase`](/type/Str#method_samecase) on it.

```raku
say "raKu".samecase("A_a_"); # OUTPUT: «Raku␤»
say "rAKU".samecase("Ab");   # OUTPUT: «Raku␤»
```

## [routine uniprop](#class_Cool "go to top of document")[§](#routine_uniprop "direct link")

```raku
multi        uniprop(Str:D, |c)
multi        uniprop(Int:D $code)
multi        uniprop(Int:D $code, Stringy:D $propname)
multi method uniprop(|c)
```

Returns the [unicode property](https://en.wikipedia.org/wiki/Unicode_character_property) of the first character. If no property is specified returns the [General Category](https://en.wikipedia.org/wiki/Unicode_character_property#General_Category). Returns a Bool for Boolean properties. A [uniprops](/routine/uniprops) routine can be used to get the property for every character in a string.

```raku
say 'a'.uniprop;               # OUTPUT: «Ll␤»
say '1'.uniprop;               # OUTPUT: «Nd␤»
say 'a'.uniprop('Alphabetic'); # OUTPUT: «True␤»
say '1'.uniprop('Alphabetic'); # OUTPUT: «False␤»
```

## [sub uniprops](#class_Cool "go to top of document")[§](#sub_uniprops "direct link")

```raku
sub uniprops(Str:D $str, Stringy:D $propname = "General_Category")
```

Interprets the invocant as a [`Str`](/type/Str), and returns the [unicode property](http://userguide.icu-project.org/strings/properties) for each character as a Seq. If no property is specified returns the [General Category](https://en.wikipedia.org/wiki/Unicode_character_property#General_Category). Returns a Bool for Boolean properties. Similar to [uniprop](/routine/uniprop), but for each character in the passed string.

## [routine uniname](#class_Cool "go to top of document")[§](#routine_uniname "direct link")

```raku
sub uniname(Str(Cool) --> Str)
method uniname(--> Str)
```

Interprets the invocant or first argument as a [`Str`](/type/Str), and returns the Unicode codepoint name of the first codepoint of the first character. See [uninames](/routine/uninames) for a routine that works with multiple codepoints, and [uniparse](/routine/uniparse) for the opposite direction.

```raku
# Camelia in Unicode
say ‘»ö«’.uniname;
# OUTPUT: «RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK␤»
say "Ḍ̇".uniname; # Note, doesn't show "COMBINING DOT ABOVE"
# OUTPUT: «LATIN CAPITAL LETTER D WITH DOT BELOW␤»

# Find the char with the longest Unicode name.
say (0..0x1FFFF).sort(*.uniname.chars)[*-1].chr.uniname;
# OUTPUT: «BOX DRAWINGS LIGHT DIAGONAL UPPER CENTRE TO MIDDLE RIGHT AND MIDDLE LEFT TO LOWER CENTRE␤»
```

Available as of the 2021.04 Rakudo compiler release.

## [routine uninames](#class_Cool "go to top of document")[§](#routine_uninames "direct link")

```raku
sub uninames(Str:D)
method uninames()
```

Returns of a [`Seq`](/type/Seq) of Unicode names for the all the codepoints in the [`Str`](/type/Str) provided.

```raku
say ‘»ö«’.uninames.raku;
# OUTPUT: «("RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK", "LATIN SMALL LETTER O WITH DIAERESIS", "LEFT-POINTING DOUBLE ANGLE QUOTATION MARK").Seq␤»
```

Note this example, which gets a [`Seq`](/type/Seq) where each element is a [`Seq`](/type/Seq) of all the codepoints in that character.

```raku
say "Ḍ̇'oh".comb>>.uninames.raku;
# OUTPUT: «(("LATIN CAPITAL LETTER D WITH DOT BELOW", "COMBINING DOT ABOVE").Seq, ("APOSTROPHE",).Seq, ("LATIN SMALL LETTER O",).Seq, ("LATIN SMALL LETTER H",).Seq)␤»
```

See [uniname](/routine/uniname) for the name of the first codepoint of the first character in the provided [`Str`](/type/Str) and [uniparse](/routine/uniparse) for the opposite direction.

## [routine unimatch](#class_Cool "go to top of document")[§](#routine_unimatch "direct link")

```raku
multi unimatch(Str:D $str, |c)
multi unimatch(Int:D $code, Stringy:D $pvalname, Stringy:D $propname = $pvalname)
```

Checks if the given integer codepoint or the first letter of the given string has a unicode property equal to the value you give. If you supply the Unicode property to be checked it will only return True if that property matches the given value.

```raku
say unimatch 'A', 'Latin';           # OUTPUT: «True␤»
say unimatch 'A', 'Latin', 'Script'; # OUTPUT: «True␤»
say unimatch 'A', 'Ll';              # OUTPUT: «False␤»
```

The last property corresponds to "lowercase letter", which explains why it returns false.

## [routine chop](#class_Cool "go to top of document")[§](#routine_chop "direct link")

```raku
sub chop(Str(Cool))
method chop()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns it with the last character removed.

```raku
say 'raku'.chop;                        # OUTPUT: «rak␤»
```

## [routine chomp](#class_Cool "go to top of document")[§](#routine_chomp "direct link")

```raku
sub chomp(Str(Cool))
method chomp()
```

Coerces the invocant (or in sub form, its argument) to [`Str`](/type/Str), and returns it with the last character removed, if it is a logical newline.

```raku
say 'ab'.chomp.chars;                   # OUTPUT: «2␤»
say "a\n".chomp.chars;                  # OUTPUT: «1␤»
```

## [routine substr](#class_Cool "go to top of document")[§](#routine_substr "direct link")

```raku
sub substr(Str(Cool) $str, |c)
method substr(|c)
```

Coerces the invocant (or in the sub form, the first argument) to [`Str`](/type/Str), and calls [Str.substr](/type/Str#routine_substr) with the arguments.

## [routine substr-rw](#class_Cool "go to top of document")[§](#routine_substr-rw "direct link")

```raku
multi method substr-rw(|) is rw
multi        substr-rw(|) is rw
```

Coerces the invocant (or in the sub form, the first argument) to [`Str`](/type/Str), and calls [Str.substr-rw](/type/Str#method_substr-rw) with the arguments.

## [routine ords](#class_Cool "go to top of document")[§](#routine_ords "direct link")

```raku
sub ords(Str(Cool) $str)
method ords()
```

Coerces the invocant (or in the sub form, the first argument) to [`Str`](/type/Str), and returns a list of Unicode codepoints for each character.

```raku
say "Camelia".ords;              # OUTPUT: «67 97 109 101 108 105 97␤»
say ords 10;                     # OUTPUT: «49 48␤»
```

This is the list-returning version of [ord](/routine/ord). The inverse operation in [chrs](/routine/chrs). If you are only interested in the number of codepoints, [codes](/routine/codes) is a possibly faster option.

## [routine chrs](#class_Cool "go to top of document")[§](#routine_chrs "direct link")

```raku
sub chrs(*@codepoints --> Str:D)
method chrs()
```

Coerces the invocant (or in the sub form, the argument list) to a list of integers, and returns the string created by interpreting each integer as a Unicode codepoint, and joining the characters.

```raku
say <67 97 109 101 108 105 97>.chrs;   # OUTPUT: «Camelia␤»
```

This is the list-input version of [chr](/routine/chr). The inverse operation is [ords](/routine/ords).

## [routine split](#class_Cool "go to top of document")[§](#routine_split "direct link")

```raku
multi        split(  Str:D $delimiter, Str(Cool) $input, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty)
multi        split(Regex:D $delimiter, Str(Cool) $input, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty)
multi        split(@delimiters, Str(Cool) $input, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty)
multi method split(  Str:D $delimiter, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty)
multi method split(Regex:D $delimiter, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty)
multi method split(@delimiters, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty)
```

[[1]](#fn1)

Coerces the invocant (or in the sub form, the second argument) to [`Str`](/type/Str), splits it into pieces based on delimiters found in the string and returns the result as a [`Seq`](/type/Seq).

If `$delimiter` is a string, it is searched for literally and not treated as a regex. You can also provide multiple delimiters by specifying them as a list, which can mix `Cool` and [`Regex`](/type/Regex) objects.

```raku
say split(';', "a;b;c").raku;               # OUTPUT: «("a", "b", "c").Seq␤»
say split(';', "a;b;c", 2).raku;            # OUTPUT: «("a", "b;c").Seq␤»

say split(';', "a;b;c,d").raku;             # OUTPUT: «("a", "b", "c,d").Seq␤»
say split(/\;/, "a;b;c,d").raku;            # OUTPUT: «("a", "b", "c,d").Seq␤»
say split(/<[;,]>/, "a;b;c,d").raku;        # OUTPUT: «("a", "b", "c", "d").Seq␤»

say split(['a', /b+/, 4], '1a2bb345').raku; # OUTPUT: «("1", "2", "3", "5").Seq␤»
```

By default, `split` omits the matches, and returns a list of only those parts of the string that did not match. Specifying one of the `:k, :v, :kv, :p` adverbs changes that. Think of the matches as a list that is interleaved with the non-matching parts.

The `:v` interleaves the values of that list, which will be either [`Match`](/type/Match) objects, if a [`Regex`](/type/Regex) was used as a matcher in the split, or [`Str`](/type/Str) objects, if a `Cool` was used as matcher. If multiple delimiters are specified, [`Match`](/type/Match) objects will be generated for all of them, unless **all** of the delimiters are `Cool`.

```raku
say 'abc'.split(/b/, :v);               # OUTPUT: «(a ｢b｣ c)␤»
say 'abc'.split('b', :v);               # OUTPUT: «(a b c)␤»
```

`:k` interleaves the keys, that is, the indexes:

```raku
say 'abc'.split(/b/, :k);               # OUTPUT: «(a 0 c)␤»
```

`:kv` adds both indexes and matches:

```raku
say 'abc'.split(/b/, :kv);               # OUTPUT: «(a 0 ｢b｣ c)␤»
```

and `:p` adds them as [`Pair`](/type/Pair)s, using the same types for values as `:v` does:

```raku
say 'abc'.split(/b/, :p);               # OUTPUT: «(a 0 => ｢b｣ c)␤»
say 'abc'.split('b', :p);               # OUTPUT: «(a 0 => b c)␤»
```

You can only use one of the `:k, :v, :kv, :p` adverbs in a single call to `split`.

Note that empty chunks are not removed from the result list. For that behavior, use the `:skip-empty` named argument:

```raku
say ("f,,b,c,d".split: /","/             ).raku;  # OUTPUT: «("f", "", "b", "c", "d").Seq␤»
say ("f,,b,c,d".split: /","/, :skip-empty).raku;  # OUTPUT: «("f", "b", "c", "d").Seq␤»
```

## [routine lines](#class_Cool "go to top of document")[§](#routine_lines "direct link")

```raku
sub lines(Str(Cool))
method lines()
```

Coerces the invocant (and in sub form, the argument) to [`Str`](/type/Str), decomposes it into lines (with the newline characters stripped), and returns the list of lines.

```raku
say lines("a\nb\n").join('|');          # OUTPUT: «a|b␤»
say "some\nmore\nlines".lines.elems;    # OUTPUT: «3␤»
```

This method can be used as part of an [`IO::Path`](/type/IO/Path) to process a file line-by-line, since [`IO::Path`](/type/IO/Path) objects inherit from `Cool`, e.g.:

```raku
for 'huge-csv'.IO.lines -> $line {
    # Do something with $line
}

# or if you'll be processing later
my @lines = 'huge-csv'.IO.lines;

```

Without any arguments, sub `lines` operates on [`$*ARGFILES`](/language/variables#$*ARGFILES).

To modify values in place use [`is copy`](/language/signatures#Parameter_traits_and_modifiers) to force a writable container.

```raku
for $*IN.lines -> $_ is copy { s/(\w+)/{$0 ~ $0}/; .say }

```

## [method words](#class_Cool "go to top of document")[§](#method_words "direct link")

```raku
method words(Cool:D: |c)
```

Coerces the invocant (or first argument, if it is called as a subroutine) to [`Str`](/type/Str), and returns a list of words that make up the string. Check [`Str.words`](/type/Str#routine_words) for additional arguments and its meaning.

```raku
say <The quick brown fox>.words.join('|');     # OUTPUT: «The|quick|brown|fox␤»
say <The quick brown fox>.words(2).join('|');  # OUTPUT: «The|quick␤»

```

`Cool` is the base class for many other classes, and some of them, like [`Match`](/type/Match), can be converted to a string. This is what happens in this case:

```raku
say ( "easy come, easy goes" ~~ m:g/(ea\w+)/).words(Inf);
# OUTPUT: «(easy easy)␤»
say words( "easy come, easy goes" ~~ m:g/(ea\w+)/ , ∞);
# OUTPUT: «(easy easy)␤»
```

The example above illustrates two of the ways `words` can be invoked, with the first argument turned into invocant by its signature. `Inf` is the default value of the second argument, so in both cases (and forms) it can be simply omitted.

Only whitespace (including no-break space) counts as word boundaries

```raku
say <Flying on a Boeing 747>.words.join('|');  # OUTPUT: «Flying|on|a|Boeing|747␤»
```

In this case, "Boeing 747" includes a (visible only in the source) no-break space; `words` still splits the (resulting) [`Str`](/type/Str) on it, even if the original array only had 4 elements:

```raku
say <Flying on a Boeing 747>.join('|');        # OUTPUT: «Flying|on|a|Boeing 747␤»
```

Please see [`Str.words`](/type/Str#routine_words) for more examples and ways to invoke it.

## [routine comb](#class_Cool "go to top of document")[§](#routine_comb "direct link")

```raku
multi        comb(Regex $matcher, Cool $input, $limit = *)
multi        comb(Str $matcher, Cool $input, $limit = *)
multi        comb(Int:D $size, Cool $input, $limit = *)
multi method comb(|c)
```

Returns a [`Seq`](/type/Seq) of all (or if supplied, at most `$limit`) matches of the invocant (method form) or the second argument (sub form) against the [`Regex`](/type/Regex), string or defined number.

```raku
say "6 or 12".comb(/\d+/).join(", ");           # OUTPUT: «6, 12␤»
say comb(/\d <[1..9]> /,(11..30)).join("--");
# OUTPUT:
# «11--12--13--14--15--16--17--18--19--21--22--23--24--25--26--27--28--29␤»
```

The second statement exemplifies the first form of `comb`, with a [`Regex`](/type/Regex) that excludes multiples of ten, and a [`Range`](/type/Range) (which is `Cool`) as `$input`. `comb` stringifies the [`Range`](/type/Range) before applying `.comb` on the resulting string. Check [`Str.comb`](/type/Str#routine_comb) for its effect on different kind of input strings. When the first argument is an integer, it indicates the (maximum) size of the chunks the input is going to be divided in

```raku
say comb(3,[3,33,333,3333]).join("*");  # OUTPUT: «3 3*3 3*33 *333*3␤»
```

In this case the input is a list, which after transformation to [`Str`](/type/Str) (which includes the spaces) is divided in chunks of size 3.

## [method contains](#class_Cool "go to top of document")[§](#method_contains "direct link")

```raku
method contains(Cool:D: |c)
```

Coerces the invocant to a [`Str`](/type/Str), and calls [`Str.contains`](/type/Str#method_contains) on it. Please refer to that version of the method for arguments and general syntax.

```raku
say 123.contains("2")# OUTPUT: «True␤»
```

Since [`Int`](/type/Int) is a subclass of `Cool`, `123` is coerced to a [`Str`](/type/Str) and then `contains` is called on it.

```raku
say (1,1, * + * … * > 250).contains(233)# OUTPUT: «True␤»
```

[`Seq`](/type/Seq)s are also subclasses of `Cool`, and they are stringified to a comma-separated form. In this case we are also using an [`Int`](/type/Int), which is going to be stringified also; `"233"` is included in that sequence, so it returns `True`. Please note that this sequence is not lazy; the stringification of lazy sequences does not include each and every one of their components for obvious reasons.

## [routine index](#class_Cool "go to top of document")[§](#routine_index "direct link")

```raku
multi        index(Cool:D $s, Cool:D $needle, :i(:$ignorecase), :m(:$ignoremark) --> Int:D)
multi        index(Cool:D $s, Cool:D $needle, Cool:D $pos, :i(:$ignorecase), :m(:$ignoremark) --> Int:D)
multi method index(Cool:D: Cool:D $needle --> Int:D)
multi method index(Cool:D: Cool:D $needle, :m(:$ignoremark)! --> Int:D)
multi method index(Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark) --> Int:D)
multi method index(Cool:D: Cool:D $needle, Cool:D $pos --> Int:D)
multi method index(Cool:D: Cool:D $needle, Cool:D $pos, :m(:$ignoremark)!  --> Int:D)
multi method index(Cool:D: Cool:D $needle, Cool:D $pos, :i(:$ignorecase)!, :m(:$ignoremark) --> Int:D)
```

Coerces the first two arguments (in method form, also counting the invocant) to a [`Str`](/type/Str), and searches for `$needle` in the string `$s` starting from `$pos`. It returns the offset into the string where `$needle` was found, and [`Nil`](/type/Nil) if it was not found.

See [the documentation in type Str](/type/Str#method_index) for examples.

## [routine rindex](#class_Cool "go to top of document")[§](#routine_rindex "direct link")

```raku
multi        rindex(Cool:D $s, Cool:D $needle --> Int:D)
multi        rindex(Cool:D $s, Cool:D $needle, Cool:D $pos --> Int:D)
multi method rindex(Cool:D: Cool:D $needle --> Int:D)
multi method rindex(Cool:D: Cool:D $needle, Cool:D $pos --> Int:D)
```

Coerces the first two arguments (including the invocant in method form) to [`Str`](/type/Str) and `$pos` to [`Int`](/type/Int), and returns the last position of `$needle` in the string not after `$pos`. Returns [`Nil`](/type/Nil) if `$needle` wasn't found.

See [the documentation in type Str](/type/Str#routine_rindex) for examples.

## [method match](#class_Cool "go to top of document")[§](#method_match "direct link")

```raku
method match(Cool:D: $target, *%adverbs)
```

Coerces the invocant to [`Stringy`](/type/Stringy) and calls the method [match](/type/Str#method_match) on it.

## [routine roots](#class_Cool "go to top of document")[§](#routine_roots "direct link")

```raku
multi        roots(Numeric(Cool) $x, Int(Cool) $n)
multi method roots(Int(Cool) $n)
```

Coerces the first argument (and in method form, the invocant) to [`Numeric`](/type/Numeric) and the second (`$n`) to [`Int`](/type/Int), and produces a list of `$n` [`Complex`](/type/Complex) `$n`-roots, which means numbers that, raised to the `$n`th power, approximately produce the original number.

For example

```raku
my $original = 16;
my @roots = $original.roots(4);
say @roots;

for @roots -> $r {
    say abs($r ** 4 - $original);
}

# OUTPUT:«2+0i 1.22464679914735e-16+2i -2+2.44929359829471e-16i -3.67394039744206e-16-2i␤»
# OUTPUT:«1.77635683940025e-15␤»
# OUTPUT:«4.30267170434156e-15␤»
# OUTPUT:«8.03651692704705e-15␤»
# OUTPUT:«1.04441561648202e-14␤»

```

## [method subst](#class_Cool "go to top of document")[§](#method_subst "direct link")

```raku
method subst(|)
```

Coerces the invocant to [`Stringy`](/type/Stringy) and calls


## 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`.*


## dist_zef-lizmat-Repository-Precomp-Cleanup.md
[![Actions Status](https://github.com/lizmat/Repository-Precomp-Cleanup/actions/workflows/test.yml/badge.svg)](https://github.com/lizmat/Repository-Precomp-Cleanup/actions)

# NAME

Repository::Precomp::Cleanup - provide logic for cleaning up precomp directories

# SYNOPSIS

```
use Repository::Precomp::Cleanup;

cleanup-precomp($*REPO);          # cleanup first repository only

my int $cleaned;
for $*REPO.repo-chain -> $repo {  # cleanup all repositories
    $cleaned += $_ with cleanup-precomp($repo);
}
say "Freed up $cleaned bytes in total";

```

# DESCRIPTION

`Repository::Precomp::Cleanup` is a module that exports a `cleanup-precomp` subroutine that will remove all outdated precompiled files from a given repository precompilation-store. It returns the number of bytes that were freed (as reported by `IO::Path.s`).

# SCRIPTS

This distribution also installs a `clean-precomp` script that will either cleanup the specified repositories by name, or all repositories that can be cleaned from the current repository chain.

# WHY

If you are a module developer that tries to keep up-to-date with all latest versions of Rakudo, and/or you're a core developer working on the setting, you can easily lose a lot of disk-space by outdated precompilation files (as each precompilation file is keyed to a specific version of the core).

The script provided by this distribution, allows you to easily free up this disk-space without having to wonder what can be removed, and what cannot.

```
$ clean-precomp

```

Clean out all precompilation stores in the current repository chain.

```
$ clean-precomp . lib

```

Clean out precompilation stores of repositories in "." and "lib".

# AUTHOR

Elizabeth Mattijsen [liz@raku.rocks](mailto:liz@raku.rocks)

Source can be located at: <https://github.com/lizmat/Repository-Precomp-Cleanup> . Comments and Pull Requests are welcome.

# COPYRIGHT AND LICENSE

Copyright 2022 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.


## dist_zef-lizmat-P5caller.md
[![Actions Status](https://github.com/lizmat/P5caller/workflows/test/badge.svg)](https://github.com/lizmat/P5caller/actions)

# NAME

Raku port of Perl's caller() built-in

# SYNOPSIS

```
use P5caller;

sub foo { bar }
sub bar { say caller[3] }        # foo

sub baz { say caller(:scalar) }  # GLOBAL
my $package = caller

```

# DESCRIPTION

This module tries to mimic the behaviour of Perl's `caller` built-in as closely as possible in the Raku Programming Language.

# ORIGINAL PERL 5 DOCUMENTATION

```
caller EXPR
caller  Returns the context of the current pure perl subroutine call. In
        scalar context, returns the caller's package name if there is a
        caller (that is, if we're in a subroutine or "eval" or "require")
        and the undefined value otherwise. caller never returns XS subs
        and they are skipped. The next pure perl sub will appear instead
        of the XS sub in caller's return values. In list context, caller
        returns

            # 0         1          2
            ($package, $filename, $line) = caller;

        With EXPR, it returns some extra information that the debugger
        uses to print a stack trace. The value of EXPR indicates how many
        call frames to go back before the current one.

            #  0         1          2      3            4
            ($package, $filename, $line, $subroutine, $hasargs,

            #  5          6          7            8       9         10
            $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
             = caller($i);

        Here, $subroutine is the function that the caller called (rather
        than the function containing the caller). Note that $subroutine
        may be "(eval)" if the frame is not a subroutine call, but an
        "eval". In such a case additional elements $evaltext and
        $is_require are set: $is_require is true if the frame is created
        by a "require" or "use" statement, $evaltext contains the text of
        the "eval EXPR" statement. In particular, for an "eval BLOCK"
        statement, $subroutine is "(eval)", but $evaltext is undefined.
        (Note also that each "use" statement creates a "require" frame
        inside an "eval EXPR" frame.) $subroutine may also be "(unknown)"
        if this particular subroutine happens to have been deleted from
        the symbol table. $hasargs is true if a new instance of @_ was set
        up for the frame. $hints and $bitmask contain pragmatic hints that
        the caller was compiled with. $hints corresponds to $^H, and
        $bitmask corresponds to "${^WARNING_BITS}". The $hints and
        $bitmask values are subject to change between versions of Perl,
        and are not meant for external use.

        $hinthash is a reference to a hash containing the value of "%^H"
        when the caller was compiled, or "undef" if "%^H" was empty. Do
        not modify the values of this hash, as they are the actual values
        stored in the optree.

        Furthermore, when called from within the DB package in list
        context, and with an argument, caller returns more detailed
        information: it sets the list variable @DB::args to be the
        arguments with which the subroutine was invoked.

        Be aware that the optimizer might have optimized call frames away
        before "caller" had a chance to get the information. That means
        that caller(N) might not return information about the call frame
        you expect it to, for "N > 1". In particular, @DB::args might have
        information from the previous time "caller" was called.

        Be aware that setting @DB::args is best effort, intended for
        debugging or generating backtraces, and should not be relied upon.
        In particular, as @_ contains aliases to the caller's arguments,
        Perl does not take a copy of @_, so @DB::args will contain
        modifications the subroutine makes to @_ or its contents, not the
        original values at call time. @DB::args, like @_, does not hold
        explicit references to its elements, so under certain cases its
        elements may have become freed and reallocated for other variables
        or temporary values. Finally, a side effect of the current
        implementation is that the effects of "shift @_" can normally be
        undone (but not "pop @_" or other splicing, and not if a reference
        to @_ has been taken, and subject to the caveat about reallocated
        elements), so @DB::args is actually a hybrid of the current state
        and initial state of @_. Buyer beware.

```

# PORTING CAVEATS

In Perl, `caller` can return an 11 element list. In the Raku implementation only the first 4 elements are the same as in Perl: package, filename, line, subname. The fifth element is actually the `Sub` or `Method` object and as such provides further introspection possibilities not found in Perl.

As there is no such thing as `scalar` or `list` context in Raku, one must specify a `:scalar` named parameter to emulate the scalar context return value.

# AUTHOR

Elizabeth Mattijsen [liz@raku.rocks](mailto:liz@raku.rocks)

If you like this module, or what I’m doing more generally, committing to a [small sponsorship](https://github.com/sponsors/lizmat/) would mean a great deal to me!

Source can be located at: <https://github.com/lizmat/P5caller> . Comments and Pull Requests are welcome.

# COPYRIGHT AND LICENSE

Copyright 2018, 2019, 2020, 2021, 2023 Elizabeth Mattijsen

Re-imagined from Perl as part of the CPAN Butterfly Plan.

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.


## none.md
none

Combined from primary sources listed below.

# [In Any](#___top "go to top of document")[§](#(Any)_method_none "direct link")

See primary documentation
[in context](/type/Any#method_none)
for **method none**.

```raku
method none(--> Junction:D)
```

Interprets the invocant as a list and creates a [none](/routine/none)-[`Junction`](/type/Junction) from it.

```raku
say so 1 == (1, 2, 3).none;     # OUTPUT: «False␤»
say so 4 == (1, 2, 3).none;     # OUTPUT: «True␤»
```


## dist_cpan-LEONT-Getopt-Subcommands.md
[![Build Status](https://travis-ci.org/Leont/getopt-subcommands.svg?branch=master)](https://travis-ci.org/Leont/getopt-subcommands)

# NAME

Getopt::Subcommands - A Getopt::Long extension for subcommands

# SYNOPSIS

```
use Getopt::Subcommands;

sub frobnicate(*@files, Bool :$dry-run) is command { ... }

sub unfrobnicate(:$fuzzy) is command { ... }

sub other($subcommand?, *@args) is fallback { ... }

```

# DESCRIPTION

Getopt::Subcommands is an extension to Getopt::Long that facilitates writing programs with multiple subcommands. It dispatches based on the first argument.

It can be used by using two traits on the subs: `is command` and `is fallback`. The former can optionally take the name of the subcommand as an argument, but will default to the name of the sub. The latter will be called if no suitable subcommand can be found or if none is given.

# AUTHOR

Leon Timmermans [fawaka@gmail.com](mailto:fawaka@gmail.com)

# COPYRIGHT AND LICENSE

Copyright 2019 Leon Timmermans

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.


## exception.md
exception

Combined from primary sources listed below.

# [In Failure](#___top "go to top of document")[§](#(Failure)_method_exception "direct link")

See primary documentation
[in context](/type/Failure#method_exception)
for **method exception**.

```raku
method exception(Failure:D: --> Exception)
```

Returns the [`Exception`](/type/Exception) object that the failure wraps.

```raku
sub failer() { fail };
my $failure = failer;
my $ex = $failure.exception;
put "$ex.^name(): $ex";
# OUTPUT: «X::AdHoc: Failed␤»
```


## tail.md
tail

Combined from primary sources listed below.

# [In Any](#___top "go to top of document")[§](#(Any)_routine_tail "direct link")

See primary documentation
[in context](/type/Any#routine_tail)
for **routine tail**.

```raku
multi method tail() is raw
multi method tail($n)
```

Returns the last or the list of the `$n` last elements of an object. `$n` can be a [`Callable`](/type/Callable), usually a [`WhateverCode`](/type/WhateverCode), which will be used to get all but the first `n` elements of the object.

```raku
say (^12).reverse.tail ;     # OUTPUT: «0␤»
say (^12).reverse.tail(3);   # OUTPUT: «(2 1 0)␤»
say (^12).reverse.tail(*-7); # OUTPUT: «(4 3 2 1 0)␤»

```

As of release 2022.07 of the Rakudo compiler, there is also a "sub" version of `tail`.

```raku
multi tail(\specifier, +values)
```

It **must** have the tail specifier as the first argument. The rest of the arguments are turned into a [`Seq`](/type/Seq) and then have the `tail` method called on it.

# [In List](#___top "go to top of document")[§](#(List)_method_tail "direct link")

See primary documentation
[in context](/type/List#method_tail)
for **method tail**.

```raku
multi method tail(List:D:)
multi method tail(List:D: $n --> Seq:D)
```

Returns a [`Seq`](/type/Seq) containing the **last** `$n` items of the list. Returns an empty [`Seq`](/type/Seq) if `$n` <= 0. Defaults to the last element if no argument is specified. Throws an exception if the list is lazy.

Examples:

```raku
say <a b c d e>.tail(*-3);# OUTPUT: «(d e)␤»
say <a b c d e>.tail(2);  # OUTPUT: «(d e)␤»
say <a b c d e>.tail;     # OUTPUT: «e␤»

```

In the first case, `$n` is taking the shape of a [`WhateverCode`](/type/WhateverCode) to indicate the number of elements from the beginning that will be excluded. `$n` can be either a Callable, in which case it will be called with the value `0`, or anything else that can be converted to a number, in which case it will use that as the number of elements in the output [`Seq`](/type/Seq).

```raku
say <a b c d e>.tail( { $_ - 2 } ); # OUTPUT: «(c d e)␤»
```

# [In Supply](#___top "go to top of document")[§](#(Supply)_method_tail "direct link")

See primary documentation
[in context](/type/Supply#method_tail)
for **method tail**.

```raku
multi method tail(Supply:D:)
multi method tail(Supply:D: Callable:D $limit)
multi method tail(Supply:D: \limit)
```

Creates a "tail" supply with the same semantics as [List.tail](/type/List#method_tail).

```raku
my $s = Supply.from-list(4, 10, 3, 2);
my $ts = $s.tail(2);
$ts.tap(&say);           # OUTPUT: «3␤2␤»
```

You can call `.tail` with [`Whatever`](/type/Whatever) or `Inf`; which will return a new supply equivalent to the initial one. Calling it with a [`WhateverCode`](/type/WhateverCode) will be equivalent to skipping until that number.

```raku
my $s = Supply.from-list(4, 10, 3, 2);
my $ts = $s.tail( * - 2 );
$ts.tap(&say);           # OUTPUT: «3␤2␤»
```

This feature is only available from the 2020.07 release of Raku.