class IO::Path

File or directory path

The workhorse of IO operations.

Conceptually, an IO::Path object consists of a volume, a directory, and a basename. It supports both purely textual operations, and operations that access the file system, e.g. to resolve a path, or to read all content of a file.

method dirname

Defined as:

Returns the directory name portion of the path object. That is, it returns the path excluding the volume and the base name.

method volume

Defined as:

Returns the volume portion of the path object. On Unix system, this is always the empty string.

method parts

Defined as:

Returns a Map with the keys volume, dirname, basename whose values are the same as available via methods .volume, .dirname, and .basename respectively.

method perl

Defined as:

Returns a string that, when given passed through EVAL gives the original invocant back.

method succ

Defined as:

Returns a new IO::Path constructed from the invocant, with .basename changed by calling Str.succ on it.

method open

Defined as:

Opens the path as a file; the named options control the mode, and are the same as the open function accepts.

method pred

Defined as:

Returns a new IO::Path constructed from the invocant, with .basename changed by calling Str.pred on it.

method watch

Defined as:

Equivalent to calling IO::Notification.watch-path with the invocant as the argument.

method is-absolute

Defined as:

Returns True if the path is an absolute path, and False otherwise.

Note that on Windows a path that starts with a slash or backslash is still considered absolute even if no volume was given, as it is absolute for that particular volume:

method is-relative

Defined as:

Returns True if the path is a relative path, and False otherwise. Windows caveats for .is-absolute apply.

Defined as:

method e

Defined as:

Returns True if the invocant is a path that exists.

TIP: use smartmatch with Pairs to perform multiple file tests.

method d

Defined as:

Returns True if the invocant is a path that exists and is a directory. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method f

Defined as:

Returns True if the invocant is a path that exists and is a file. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method s

Defined as:

Returns the file size in bytes. May be called on paths that are directories, in which case the reported size is dependent on the operating system. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method l

Defined as:

Returns True if the invocant is a path that exists and is a symlink. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method r

Defined as:

Returns True if the invocant is a path that exists and is accessible. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method w

Defined as:

Returns True if the invocant is a path that exists and is writable. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method rw

Defined as:

Returns True if the invocant is a path that exists and is readable and writable. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method x

Defined as:

Returns True if the invocant is a path that exists and is executable. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method rwx

Defined as:

Returns True if the invocant is a path that exists and is executable, readable, and writable. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method z

Defined as:

Returns True if the invocant is a path that exists and has size of 0. May be called on paths that are directories, in which case the reported file size (and thus the result of this method) is dependent on the operating system. The method will fail with X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

TIP: use smartmatch with Pairs to perform multiple file tests.

method sibling

Defined as:

Allows to reference a sibling file or directory. Returns a new IO::Path based on the invocant, with the .basename changed to $sibling. The $sibling is allowed to be a multi-part path fragment; see also .add.

method words

Defined as:

Opens the invocant and returns its words.

The behaviour is equivalent to opening the file specified by the invocant, forwarding the :$chomp, :$enc, and :$nl-in arguments to IO::Handle.open, then calling IO::Handle.words on that handle, forwarding any of the remaining arguments to that method, and returning the resultant Seq. NOTE: the words are ready lazily and the handle used under the hood won't get closed until the returned Seq is fully reified, so ensure it is, or you'll be leaking open file handles. (TIP: use the $limit argument)

method lines

Defined as:

Opens the invocant and returns its lines.

The behaviour is equivalent to opening the file specified by the invocant, forwarding the :$chomp, :$enc, and :$nl-in arguments to IO::Handle.open, then calling IO::Handle.lines on that handle, forwarding any of the remaining arguments to that method, and returning the resultant Seq. NOTE: the lines are ready lazily and the handle used under the hood won't get closed until the returned Seq is fully reified, so ensure it is, or you'll be leaking open file handles. (TIP: use the $limit argument)

Defined as:

Read all of the file's content and return it as either Buf, if :$bin is True, or if not, as Str decoded with :$enc encoding, which defaults to utf8. See &open for valid values for :$enc. method spurt Defined as: Opens the file path for writing, and writes all of the $data into it. Will fail if it cannot succeed for any reason. The $data can be any Cool type or any Blob type. Arguments are as follows: • :$enc — character encoding of the data. Takes same values as :$enc in IO::Handle.open. Defaults to utf8. Ignored if $data is a Blob.

• :$append — open the file in append mode, preserving existing contents, and appending data to the end of the file. • :$createonlyfail if the file already exists.

method chdir

Defined as:

DEPRECATION NOTICE: this method will be deprecated in 6.d language and removed in 6.e. Do not use it for new code. Instead, create a new path or use add method. For altering current working directory see &chdir and &*chdir subroutines.

Contrary to the name, the .chdir method does not change any directories, but merely concatenates the given $path to the invocant and returns the resultant IO::Path. Optional file tests can be performed by providing :d, :r, :w, or :x Bool named arguments; when set to True, they'll perform .d, .r, .w, and .x tests respectively. By default, only :d is set to True. routine mkdir Defined as: Creates a new directory. See mode for explanation and valid values for $mode. Returns the IO::Path object pointing to the newly created directory on success; fails with X::IO::Mkdir if directory cannot be created.

Creates parent directories, as needed (similar to *nix utility mkdir with -p option). That is, mkdir "foo/bar/ber/meow" will create foo, foo/bar, and foo/bar/ber directories if they do not exist, as well as create foo/bar/ber/meow.

routine rmdir

Defined as:

Remove the invocant, or in sub form, all of the provided directories in the given list, which can contain any Cool object. Only works on empty directories.

Method form returns True on success and throws an exception of type X::IO::Rmdir if the directory cannot be removed (e.g. the directory is not empty, or the path is not a directory). Subroutine form returns a list of directories that were successfully deleted.

To delete non-empty directory, see rmtree in File::Directory::Tree module.

Defined as:

Changes the POSIX permissions of a file or directory to $mode. Returns True on success; on failure, fails with X::IO::Chmod. The mode is expected as an integer following the standard numeric notation, and is best written as an octal number: Make sure you don't accidentally pass the intended octal digits as a decimal number (or string containing a decimal number): routine rename Defined as: Renames a file or directory. Returns True on success; fails with X::IO::Rename if :$createonly is True and the $to path already exists or if the operation failed for some other reason. Note: some renames will always fail, such as when the new name is on a different storage device. See also: move. routine copy Defined as: Copies a file. Returns True on success; fails with X::IO::Copy if :$createonly is True and the $to path already exists or if the operation failed for some other reason, such as when $to and $from are the same file. routine move Defined as: Copies a file and then removes the original. If removal fails, it's possible to end up with two copies of the file. Returns True on success; fails with X::IO::Move if :$createonly is True and the $to path already exists or if the operation failed for some other reason, such as when $to and $from are the same file. To avoid copying, you can use rename, if the files are on the same storage device. It also works with directories, while move does not. method Numeric Defined as: Coerces .basename to Numeric. Fails with X::Str::Numeric if base name is not numerical. method Int Defined as: Coerces .basename to Int. Fails with X::Str::Numeric if base name is not numerical. Defined as: Create a new symbolic link $link to existing $target. Returns True on success; fails with X::IO::Symlink if the symbolic link could not be created. If $target does not exist, creates a dangling symbolic link. To create a hard link, see link.

Note: on Windows, creation of symbolic links may require escalated privileges.

Defined as:

Create a new hard link $link to existing $target. Returns True on success; fails with X::IO::Link if the hard link could not be created. To create a symbolic link, see symlink.

Defined as:

Delete all specified ordinary files, links, or symbolic links. See rmdir to delete directories.

The subroutine form returns the names of the files that were successfully deleted. The method form returns True on success, or fails with X::IO::Unlink if the operation could not be completed.

method IO

Defined as:

Returns the invocant.

method SPEC

Defined as:

Returns the IO::Spec object that was (implicitly) specified at object creation time.

File timestamp retrieval

There are also 3 methods for fetching the 3 timestamps of a file (inode), on Operating Systems where these are available:

method modified

Returns an Instant object indicating when the file was last modified.

method accessed

Return an Instant object representing the timestamp when the file was last accessed. Note: depending on how the filesystem was mounted, the last accessed time may not update on each access to the file, but only on the first access after modifications.

method changed

Returns an Instant object indicating the file or directory was last changed.

File permissions retrieval

method mode

Return an IntStr object representing the POSIX permissions of a file. The Str part of the result is the octal representation of the file permission, like the form accepted by the chmod(1) utility.

The result of this can be used in the other methods that take a mode as an argument.

Routines supplied by role IO

IO::Path does role IO, which provides the following methods:

(IO) sub chdir

Defined as:

Changes value of $*CWD variable to the provided $path, optionally ensuring the new path passes several file tests. NOTE: that this routine does NOT alter the process's current directory (see &*chdir).

(IO) sub indir

Defined as:

Takes Callable &code and executes it after locally (to &code) changing $*CWD variable to an IO::Path object based on $path, optionally ensuring the new path passes several file tests. If $path is relative, it will be turned into an absolute path, even if an IO::Path object was given. NOTE: that this routine does NOT alter the process's current directory (see &*chdir). The $*CWD outside of the &code is not affected, even if &code explicitly assigns a new value to $*CWD. Returns the return value of &code on success. On failure to successfully change $*CWD, returns Failure. WARNING: keep in mind that lazily evaluated things might end up NOT having the $*CWD set by indir in their dynamic scope by the time they're actually evaluated. Either ensure the generators have their $*CWD set or eagerly evaluate them before returning the results from indir:

The routine's $path argument can be any object with an IO method that returns an IO::Path object. The available file tests are: • :d — check .d returns True • :r — check .r returns True • :w — check .w returns True • :x — check .x returns True • By default, only :d test is performed. (IO) sub print Defined as: Prints the given text on standard output (the $*OUT file handle), coercing non-Str objects to Str by calling .Str method:

To print text and include the trailing newline, use put.

Defined as:

(IO) sub slurp

Slurps the contents of the entire file into a Str (or Buf if :bin). Accepts :bin and :enc optional named parameters, with the same meaning as open(). The routine will fail if the file does not exist, or is a directory.

(IO) sub spurt

Defined as:

The $path can be any object with an IO method that returns an IO::Path object. Calls IO::Path.spurt on the $path, forwarding any of the remaining arguments.

Options

• :enc

• The encoding with which the contents will be written.

• :bin

• Open the file in binary mode.

• :append

• Boolean indicating whether to append to a (potentially) existing file. If the file did not exist yet, it will be created. Defaults to False.

• :createonly

• Boolean indicating whether to fail if the file already exists. Defaults to False.

(IO) sub run

Runs an external command without involving a shell and returns a Proc object.

To capture output or error you can use the :out or :err arguments respectively:

See Proc and Proc::Async for more details.

(IO) sub shell

Runs a command through the system shell. All shell meta characters are interpreted by the shell, including pipes, redirects, environment variable substitutions and so on. Shell escapes are a severe security concern and can cause confusion with unusual file names. Use run if you want to be safe.

The return value is of type Proc.

See Proc for more details, for example on how to capture output.

Routines supplied by class Cool

IO::Path inherits from class Cool, which provides the following methods:

(Cool) routine abs

Defined as:

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

(Cool) method conj

Defined as:

Coerces the invocant to Numeric and returns the complex conjugate (that is, the number with the sign of the imaginary part negated).

(Cool) routine sqrt

Defined as:

Coerces the invocant to Numeric (or in the sub form, the argument) and returns the square root, that is, a non-negative number that, when multiplied with itself, produces the original number.

(Cool) method sign

Defined as:

Coerces the invocant to Numeric and returns its sign, that is, 0 if the number is 0, 1 for positive and -1 for negative values.

(Cool) method rand

Defined as:

Coerces the invocant to Num and returns a pseudo-random value between zero and the number.

(Cool) routine sin

Defined as:

Coerces the invocant (or in the sub form, the argument) to Numeric, interprets it as radians, returns its sine.

Note that Perl 6 is no computer algebra system, so sin(pi) typically does not produce an exact 0, but rather a very small floating-point number.

(Cool) routine asin

Defined as:

Coerces the invocant (or in the sub form, the argument) to Numeric, and returns its arc-sine in radians.

(Cool) routine cos

Defined as:

Coerces the invocant (or in sub form, the argument) to Numeric, interprets it as radians, returns its cosine.

(Cool) routine acos

Defined as:

Coerces the invocant (or in sub form, the argument) to Numeric, and returns its arc-cosine in radians.

(Cool) routine tan

Defined as:

Coerces the invocant (or in sub form, the argument) to Numeric, interprets it as radians, returns its tangent.

(Cool) routine atan

Defined as:

Coerces the invocant (or in sub form, the argument) to Numeric, and returns its arc-tangent in radians.

(Cool) routine atan2

Defined as:

Coerces the arguments (including the invocant in the method form) to Numeric, and returns their two-argument arc-tangent in radians.

(Cool) method sec

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, interprets it as radians, returns its secant, that is, the reciprocal of its cosine.

(Cool) routine asec

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its arc-secant in radians.

(Cool) routine cosec

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, interprets it as radians, returns its cosecant, that is, the reciprocal of its sine.

(Cool) routine acosec

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its arc-cosecant in radians.

(Cool) routine cotan

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, interprets it as radians, returns its cotangent, that is, the reciprocal of its tangent.

(Cool) routine acotan

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its arc-cotangent in radians.

(Cool) routine sinh

Defined as:

Coerces the invocant (or in method form, its argument) to Numeric, and returns its Sine hyperbolicus.

(Cool) routine asinh

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Inverse Sine hyperbolicus.

(Cool) routine cosh

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Cosine hyperbolicus.

(Cool) routine acosh

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Inverse Cosine hyperbolicus.

(Cool) routine tanh

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, interprets it as radians and returns its Tangent hyperbolicus.

(Cool) routine atanh

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Inverse tangent hyperbolicus.

(Cool) routine sech

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Secant hyperbolicus.

(Cool) routine asech

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Inverse hyperbolic secant.

(Cool) routine cosech

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Hyperbolic cosecant.

(Cool) routine acosech

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Inverse hyperbolic cosecant.

(Cool) routine cotanh

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Hyperbolic cotangent.

(Cool) routine acotanh

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns its Inverse hyperbolic cotangent.

(Cool) routine cis

Defined as:

Coerces the invocant (or in sub form, its argument) to Numeric, and returns cos(argument) + i*sin(argument).

Defined as:

Coerces the arguments (including the invocant in the method form) to Numeric, and returns its Logarithm to base $base, or to base e (Euler's Number) if no base was supplied (Natural logarithm). Returns NaN if $base is negative. Throws an exception if $base is 1. (Cool) routine log10 Defined as: Coerces the invocant (or in the sub form, the invocant) to Numeric, and returns its Logarithm to base 10, that is, a number that approximately produces the original number when raised to the power of 10. Returns NaN for negative arguments and -Inf for 0. (Cool) method exp Defined as: Coerces the arguments (including the invocant in the method from) to Numeric, and returns $base raised to the power of the first number. If no $base is supplied, e (Euler's Number) is used. (Cool) method unpolar Defined as: Coerces the arguments (including the invocant in the method form) to 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. (Cool) routine round Defined as: Coerces the invocant (or in sub form, its argument) to Numeric, and rounds it to the unit of $unit. If $unit is 1, rounds to the nearest integer. Always rounds up if the number is at mid-point: (Cool) routine floor Defined as: Coerces the invocant (or in sub form, its argument) to Numeric, and rounds it downwards to the nearest integer. (Cool) routine ceiling Defined as: Coerces the invocant (or in sub form, its argument) to Numeric, and rounds it upwards to the nearest integer. (Cool) routine truncate Defined as: Coerces the invocant (or in sub form, its argument) to Numeric, and rounds it towards zero. (Cool) routine ord Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns the Unicode code point number of the first code point. The inverse operation is chr. Mnemonic: returns an ordinal number (Cool) routine chr Defined as: Coerces the invocant (or in sub form, its argument) to Int, interprets it as a Unicode code points, and returns a string made of that code point. The inverse operation is ord. Mnemonic: turns an integer into a character. (Cool) routine chars Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns the number of characters in the string. Please note that on the JVM, you currently get codepoints instead of graphemes. (Cool) routine codes Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns the number of Unicode code points. (Cool) routine flip Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns a reversed version. (Cool) routine trim Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns the string with both leading and trailing whitespace stripped. (Cool) routine trim-leading Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns the string with leading whitespace stripped. (Cool) routine trim-trailing Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns the string with trailing whitespace stripped. (Cool) routine lc Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns it case-folded to lower case. (Cool) routine uc Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns it case-folded to upper case (capital letters). (Cool) routine fc Defined as: Coerces the invocant (or in sub form, its argument) to 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.) (Cool) routine tc Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns it with the first letter case-folded to title case (or where not available, upper case). (Cool) routine tclc Defined as: Coerces the invocant (or in sub form, its argument) to Str, and returns it with the first letter case-folded to title case (or where not available, upper case), and the rest of the string case-folded to lower case.. (Cool) routine wordcase Defined as: Coerces the invocant (or in sub form, the first argument) to Str, and filters each word that smart-matches against $where through the &filter. With the default filter (first character to upper case, rest to lower) and matcher (which accepts everything), this title-cases each word:

With a matcher:

With a customer filter too:

Defined as:

If the $from parameter is a Callable, it is called with the number of chars in the string as argument. This allows easy indexing relative to the end: (Cool) routine ords Defined as: Coerces the invocant (or in the sub form, the first argument) to Str, and returns a list of Unicode codepoints for each character. This is the list-returning version of ord. The inverse operation in chrs. (Cool) routine chrs Defined as: 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. This is the list-input version of chr. The inverse operation is ords. (Cool) routine split Defined as: Coerces the invocant (or in the sub form, the second argument) to Str, and splits it into pieces based on delimiters found in the string. 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; mixing Cool and Regex objects is OK.

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 objects, if a Regex was used as a matcher in the split, or Str objects, if a Cool was used as matcher. If multiple delimiters are specified, Match objects will be generated for all of them, unless all of the delimiters are Cool.

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

:kv adds both indexes and matches:

and :p adds them as Pairs, using the same types for values as :v does:

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:

(Cool) routine lines

Defined as:

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

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

Without any arguments, sub lines operates on $*ARGFILES, which defaults to $*IN in the absence of any filenames.

To modify values in place use is copy to force a writable container.

(Cool) method words

Defined as:

Coerces the invocant to Str, and returns a list of words that make up the string (and if $limit is supplied, only the first $limit words).

Only whitespace counts as word boundaries

Defined as:

Returns all (or if supplied, at most $limit) matches of the invocant (method form) or the second argument (sub form) against the Regex as a list of strings. (Cool) method contains Coerces the invocant and first argument to Str, and searches for $needle in the string starting from $start. Returns True if $needle is found.

Note that because of how a List or Array is coerced into a Str, the results may sometimes be surprising. See traps.

Defined as:

Coerces the first two arguments (in method form, also counting the invocant) to Str, and searches for $needle in the string starting from $startpos. It returns the offset into the string where $needle was found, and an undefined value if it was not found. See the documentation in type Str for examples. (Cool) routine rindex Defined as: Coerces the first two arguments (including the invocant in method form) to Str and $startpos to Int, and returns the last position of $needle in $haystack not after $startpos. Returns an undefined value if $needle wasn't found.

See the documentation in type Str for examples.

(Cool) routine match

Defined as:

Coerces the invocant to Str and calls the method match on it.

Defined as:

Routines supplied by class Any

IO::Path inherits from class Any, which provides the following methods:

Defined as:

Usage:

(Any) method deepmap

Defined as:

deepmap will apply &block to each element and return a new List with the return values of &block, unless the element does the Iterable role. For those elements deepmap will descend recursively into the sublist.

(Any) method duckmap

Defined as:

duckmap will apply &block on each element and return a new list with defined return values of the block. For undefined return values, duckmap will try to descend into the element if that element implements Iterable.

(Any) method nodemap

Defined as:

nodemap will apply &block to each element and return a new List with the return values of &block. In contrast to deepmap it will not descend recursively into sublists if it finds elements which does the Iterable role.

The examples above would have produced the exact same results if we had used map instead of nodemap. The difference between the two lies in the fact that map flattens out slips while nodemap doesn't.

(Any) method flat

Defined as:

Interprets the invocant as a list, flattens non-containerized Iterables into a flat list, and returns that list. Keep in mind Map and Hash types are Iterable and so will be flattened into lists of pairs.

Note that Arrays containerize their elements by default, and so flat will not flatten them. You can use hyper method call to call .List method on all the inner Iterables and so de-containerize them, so that flat can flatten them:

For more fine-tuned options, see deepmap, duckmap, and signature destructuring

(Any) method eager

Defined as:

Interprets the invocant as a list, evaluates it eagerly, and returns that list.

(Any) method elems

Defined as:

Interprets the invocant as a list, and returns the number of elements in the list.

(Any) method end

Interprets the invocant as a list, and returns the last index of that list.

(Any) method pairup

Defined as:

Interprets the invocant as a list, and constructs a list of pairs from it, in the same way that assignment to a Hash does. That is, it takes two consecutive elements and constructs a pair from them, unless the item in the key position already is a pair (in which case the pair is passed is passed through, and the next list item, if any, is considered to be a key again).

Defined as:

(Any) method Array

Defined as:

Coerce the invocant to Array.

(Any) method List

Defined as:

Coerce the invocant to List.

(Any) method Hash

Defined as:

Coerce the invocant to Hash.

(Any) method hash

Defined as:

Coerce the invocant to Hash.

(Any) method Slip

Defined as:

Coerce the invocant to Slip.

(Any) method Map

Defined as:

Coerce the invocant to Map.

(Any) method Bag

Defined as:

Coerce the invocant to Bag, whereby Positionals are treated as lists of values.

(Any) method BagHash

Defined as:

Coerce the invocant to BagHash, whereby Positionals are treated as lists of values.

(Any) method Set

Defined as:

Coerce the invocant to Set, whereby Positionals are treated as lists of values.

(Any) method SetHash

Defined as:

Coerce the invocant to SetHash, whereby Positionals are treated as lists of values.

(Any) method Mix

Defined as:

Coerce the invocant to Mix, whereby Positionals are treated as lists of values.

(Any) method MixHash

Defined as:

Coerce the invocant to MixHash, whereby Positionals are treated as lists of values.

(Any) method Supply

Defined as:

Coerce the invocant first to a List and then to a Supply.

(Any) method min

Defined As:

Coerces to Iterable and returns the numerically smallest element.

If a Callable positional argument is provided, each value is passed into the filter, and its return value is compared instead of the original value. The original value is still the one returned from min.

(Any) method max

Defined As:

Coerces to Iterable and returns the numerically largest element.

If a Callable positional argument is provided, each value is passed into the filter, and its return value is compared instead of the original value. The original value is still the one returned from max.

(Any) method minmax

Defined As:

Returns a Range from the smallest to the largest element.

If a Callable positional argument is provided, each value is passed into the filter, and its return value is compared instead of the original value. The original values are still used in the returned Range.

(Any) method minpairs

Defined As:

Calls .pairs and returns a Seq with all of the Pairs with minimum values, as judged by the cmp operator:

(Any) method maxpairs

Defined As:

Calls .pairs and returns a Seq with all of the Pairs with maximum values, as judged by the cmp operator:

(Any) method keys

Defined As:

For defined Any returns its keys, otherwise returns an empty list.

(Any) method flatmap

Defined As:

Treats the Any as 1-item list and uses List.flatmap on it.

(Any) method roll

Defined As:

Treats the Any as 1-item list and uses List.roll on it.

(Any) method pick

Defined As:

Treats the Any as 1-item list and uses List.pick on it.

(Any) method skip

Defined As:

Creates a Seq from 1-item list's iterator and uses Seq.skip on it.

(Any) method prepend

Defined As:

Initializes Any variable as empty Array and calls Array.prepend on it.

(Any) method unshift

Defined As:

Initializes Any variable as empty Array and calls Array.unshift on it.

(Any) method first

Defined As:

Treats the Any as a 1-item list and uses List.first on it.

(Any) method unique

Defined As:

Treats the Any as a 1-item list and uses List.unique on it.

(Any) method repeated

Defined As:

Treats the Any as a 1-item list and uses List.repeated on it.

(Any) method squish

Defined As:

Treats the Any as a 1-item list and uses List.squish on it.

Defined As:

TODO

(Any) method permutations

Defined As:

Treats the Any as a 1-item list and uses List.permutations on it.

(Any) method categorize

Defined As:

Treats the Any as a 1-item list and uses List.categorize on it.

(Any) method classify

Defined As:

Treats the Any as a 1-item list and uses List.classify on it.

Defined As:

TODO

(Any) method pairs

Defined As:

Returns an empty List.

(Any) method antipairs

Defined As:

Returns an empty List.

(Any) method kv

Defined As:

Returns an empty List.

Defined As:

Returns Any.

(Any) method nl-out

Defined As:

Returns Str with the value of "\n". See IO::Handle.nl-out for the details.

(Any) method invert

Defined As:

Returns an empty List.

(Any) method combinations

Defined As:

Treats the Any as a 1-item list and uses List.combinations on it.

(Any) method iterator

Defined As:

Treats the Any as 1-item list and uses iterator on it.

(Any) method grep

Defined As:

Treats the Any as 1-item list and uses List.grep on it.

Based on $matcher value can be either ((Any)) or empty List. (Any) method append Defined As: Initializes Any variable as empty Array and calls Array.append on it. (Any) method values Defined As: Returns an empty List. (Any) method collate Defined As: TODO (Any) method cache Defined As: TODO Routines supplied by class Mu IO::Path inherits from class Mu, which provides the following methods: (Mu) routine defined Returns False on the type object, and True otherwise. Very few types (like Failure) override defined to return False even for instances: (Mu) routine isa Returns True if the invocant is an instance of class $type, a subset type or a derived class (through inheritance) of $type. A more idiomatic way to do this is to use the smartmatch operator ~~ instead. (Mu) routine does Returns True if and only if the invocant conforms to type $type.

Using the smart match operator ~~ is a more idiomatic alternative.

(Mu) routine Bool

Returns False on the type object, and True otherwise.

Many built-in types override this to be False for empty collections, the empty string or numerical zeros

(Mu) method Capture

Defined as:

Returns a Capture with named arguments corresponding to invocant's public attributes:

(Mu) method Str

Returns a string representation of the invocant, intended to be machine readable. Method Str warns on type objects, and produces the empty string.

(Mu) routine gist

Returns a string representation of the invocant, optimized for fast recognition by humans. As such lists will be truncated at 100 elements. Use .perl to get all elements.

The default gist method in Mu re-dispatches to the perl method for defined invocants, and returns the type name in parenthesis for type object invocants. Many built-in classes override the case of instances to something more specific that may truncate output.

gist is the method that say calls implicitly, for non-Str types, so say $something and say$something.gist generally produce the same output.

(Mu) routine perl

Returns a Perlish representation of the object (i.e., can usually be re-evaluated with EVAL to regenerate the object). The exact output of perl is implementation specific, since there are generally many ways to write a Perl expression that produces a particular value

(Mu) method item

Forces the invocant to be evaluated in item context and returns the value of it.

(Mu) method self

Returns the object it is called on.

(Mu) method clone

Creates a shallow clone of the invocant, including shallow cloning of private attributes. Alternative values for public attributes can be provided via named arguments with names matching the attributes' names.

Note that .clone does not go the extra mile to shallow-copy @. and %. sigiled attributes and, if modified, the modifications will still be available in the original object:

To clone those, you could implement your own .clone that clones the appropriate attributes and passes the new values to Mu.clone, for example, via nextwith. Alternatively, your own .clone could clone self first (using self.Mu::clone or callsame) and then manipulate the clone as needed, before returning it.

(Mu) method new

Default method for constructing (create + initialize) new objects of a class. This method expects only named arguments which are then used to initialize attributes with accessors of the same name.

Classes may provide their own new method to override this default.

new triggers an object construction mechanism that calls submethods named BUILD in each class of an inheritance hierarchy, if they exist. See the documentation on object construction for more information.

(Mu) method bless

Lower-level object construction method than new.

Creates a new object of the same type as the invocant, uses the named arguments to initialize attributes, and returns the created object.

You can use this method when writing custom constructors:

(Though each time you write a custom constructor, remember that it makes subclassing harder).

(Mu) method CREATE

Allocates a new object of the same type as the invocant, without initializing any attributes.

Prints value to $*OUT after stringification using gist method with newline at end. To produce machine readable output use .put. (Mu) method ACCEPTS ACCEPTS is the method that smart matching with the infix ~~ operator and given/when invokes on the right-hand side (the matcher). The Mu:U multi performs a type check. Returns True if $other conforms to the invocant (which is always a type object or failure).

Note that there is no multi for defined invocants; this is to allow autothreading of junctions, which happens as a fallback mechanism when no direct candidate is available to dispatch to.

(Mu) method WHICH

Returns an object of type ObjAt which uniquely identifies the object. Value types override this method which makes sure that two equivalent objects return the same return value from WHICH.

(Mu) method WHERE

Returns an Int representing the memory address of the object.

(Mu) method WHY

Returns the attached Pod::Block::Declarator.

For instance:

See Pod declarator blocks for details about attaching Pod to variables, classes, functions, methods, etc.

(Mu) trait is export

Marks a type as being exported, that is, available to external users.

A user of a module or class automatically gets all the symbols imported that are marked as is export.

See Exporting and Selective Importing Modules for more details.

(Mu) method return

The method return will stop execution of a subroutine or method, run all relevant phasers and provide invocant as a return value to the caller. If a return type constraint is provided it will be checked unless the return value is Nil. A control exception is raised and can be caught with CONTROL.

(Mu) method return-rw

Same as method return except that return-rw returns a writable container to the invocant (see more details here: return-rw).

(Mu) method emit

Emits the invocant into the enclosing supply or react block.

(Mu) method take

Returns the invocant in the enclosing gather block.

(Mu) routine take

Takes the given item and passes it to the enclosing gather block.

(Mu) routine take-rw

Returns the given item to the enclosing gather block, without introducing a new container.

(Mu) method so

Returns a Bool value representing the logical non-negation of an expression. One can use this method similarly to the English sentence: "If that is so, then do this thing". For instance,

(Mu) method not

Returns a Bool value representing the logical negation of an expression. Thus it is the opposite of so.

Since there is also a prefix version of not, the above code reads better like so: