txt: ## accepts.md
  ACCEPTS
  
  Combined from primary sources listed below.
  
  # [In Signature](#___top "go to top of document")[§](#(Signature)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Signature#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Signature:D: Signature $topic)
  multi method ACCEPTS(Signature:D: Capture $topic)
  multi method ACCEPTS(Signature:D: Mu \topic)
  ```
  
  If `$topic` is a `Signature` returns `True` if anything accepted by `$topic` would also be accepted by the invocant, otherwise returns `False`:
  
  ```raku
  :($a, $b) ~~ :($foo, $bar, $baz?);   # OUTPUT: «True»
  :(Int $n) ~~ :(Str);                 # OUTPUT: «False»
  ```
  
  The `$topic` is a [`Capture`](/type/Capture), returns `True` if it can be bound to the invocant, i.e., if a function with invocant's `Signature` would be able to be called with the `$topic`:
  
  ```raku
  \(1, 2, :foo) ~~ :($a, $b, :foo($bar)); # OUTPUT: «True»
  \(1, :bar)    ~~ :($a);                 # OUTPUT: «False»
  ```
  
  Lastly, the candidate with `Mu \topic` converts `topic` to [`Capture`](/type/Capture) and follows the same semantics as [`Capture`](/type/Capture) `$topic`:
  
  ```raku
  <a b c d>  ~~ :(Int $a);      # OUTPUT: «False»
  42         ~~ :(Int);         # OUTPUT: «False» (Int.Capture throws)
  set(<a b>) ~~ :(:$a, :$b);    # OUTPUT: «True»
  ```
  
  Since [`where` clauses](/language/signatures#index-entry-where_clause) are not introspectable, the method cannot determine whether two signatures [ACCEPTS](/type/Signature#method_ACCEPTS) the same sort of `where`-constrained parameters. Such comparisons will return `False`. This includes signatures with literals, which are just sugar for the `where`-constraints:
  
  ```raku
  say :(42) ~~ :($ where 42)    # OUTPUT: «False␤»
  ```
  
  # [In List](#___top "go to top of document")[§](#(List)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/List#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(List:D: $topic)
  ```
  
  If `$topic` is an [`Iterable`](/type/Iterable), returns `True` or `False` based on whether the contents of the two [`Iterable`](/type/Iterable)s match. A [`Whatever`](/type/Whatever) element in the invocant matches anything in the corresponding position of the `$topic` [`Iterable`](/type/Iterable). A [`HyperWhatever`](/type/HyperWhatever) matches any number of any elements, including no elements:
  
  ```raku
  say (1, 2, 3)       ~~ (1,  *, 3);  # OUTPUT: «True␤»
  say (1, 2, 3)       ~~ (9,  *, 5);  # OUTPUT: «False␤»
  say (1, 2, 3)       ~~ (   **, 3);  # OUTPUT: «True␤»
  say (1, 2, 3)       ~~ (   **, 5);  # OUTPUT: «False␤»
  say (1, 3)          ~~ (1, **, 3); # OUTPUT: «True␤»
  say (1, 2, 4, 5, 3) ~~ (1, **, 3); # OUTPUT: «True␤»
  say (1, 2, 4, 5, 6) ~~ (1, **, 5); # OUTPUT: «False␤»
  say (1, 2, 4, 5, 6) ~~ (   **   ); # OUTPUT: «True␤»
  say ()              ~~ (   **   ); # OUTPUT: «True␤»
  ```
  
  In addition, returns `False` if either the invocant or `$topic` [is a lazy](/routine/is-lazy) [`Iterable`](/type/Iterable), unless `$topic` is the same object as the invocant, in which case `True` is returned.
  
  If `$topic` is *not* an [`Iterable`](/type/Iterable), returns the invocant if the invocant has no elements or its first element is a [`Match`](/type/Match) object (this behavior powers `m:g//` smartmatch), or `False` otherwise.
  
  # [In role Baggy](#___top "go to top of document")[§](#(role_Baggy)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Baggy#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  method ACCEPTS($other --> Bool:D)
  ```
  
  Used in smartmatching if the right-hand side is a `Baggy`.
  
  If the right-hand side is the type object, i.e. `Baggy`, the method returns `True` if `$other` [does](/type/Mu#routine_does) `Baggy` otherwise `False` is returned.
  
  If the right-hand side is a `Baggy` object, `True` is returned only if `$other` has the same elements, with the same weights, as the invocant.
  
  ```raku
  my $breakfast = bag <eggs bacon>;
  say $breakfast ~~ Baggy;                            # OUTPUT: «True␤»
  say $breakfast.does(Baggy);                         # OUTPUT: «True␤»
  
  my $second-breakfast = (eggs => 1, bacon => 1).Mix;
  say $breakfast ~~ $second-breakfast;                # OUTPUT: «True␤»
  
  my $third-breakfast = (eggs => 1, bacon => 2).Bag;
  say $second-breakfast ~~ $third-breakfast;          # OUTPUT: «False␤»
  ```
  
  # [In enum Bool](#___top "go to top of document")[§](#(enum_Bool)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Bool#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  method ACCEPTS(Bool:D: --> Bool:D)
  ```
  
  Used for smartmatch comparison. When the right side is `True` returns always `True`, when the right side of the match is `False` returns always `False`. In particular, `ACCEPTS` returns always the instance on which it is invoked, that is the right side of a smartmatch. As an example:
  
  ```raku
  my $b = Bool.new( True );
  # when True on the right side returns
  # always True
  True  ~~ $b;     # True
  False ~~ $b;     # True
  
  $b = Bool.new( False );
  # when False on the right side
  # returns always False
  False ~~ $b;     # False
  True ~~ $b;      # False
  
  ```
  
  # [In Regex](#___top "go to top of document")[§](#(Regex)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Regex#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Regex:D: Mu --> Match:D)
  multi method ACCEPTS(Regex:D: @)
  multi method ACCEPTS(Regex:D: %)
  ```
  
  Matches the regex against the argument passed in. If the argument is [`Positional`](/type/Positional), it returns the first successful match of any list item. If the argument is [`Associative`](/type/Associative), it returns the first successful match of any key. Otherwise it interprets the argument as a [`Str`](/type/Str) and matches against it.
  
  In the case of Positional and Associative matches, [`Nil`](/type/Nil) is returned on failure.
  
  # [In Str](#___top "go to top of document")[§](#(Str)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Str#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Str:D: $other)
  ```
  
  Returns `True` if the string is [the same as](/routine/eq) `$other`.
  
  # [In Range](#___top "go to top of document")[§](#(Range)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Range#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Range:D: Mu \topic)
  multi method ACCEPTS(Range:D: Range \topic)
  multi method ACCEPTS(Range:D: Cool:D \got)
  multi method ACCEPTS(Range:D: Complex:D \got)
  ```
  
  Indicates if the `Range` contains (overlaps with) another `Range`. As an example:
  
  ```raku
  my $p = Range.new( 3, 5  );
  my $r = Range.new( 1, 10 );
  
  say $p.ACCEPTS( $r );    # OUTPUT: «False␤»
  say $r.ACCEPTS( $p );    # OUTPUT: «True␤»
  say $r ~~ $p;            # OUTPUT: «False␤»  (same as $p.ACCEPTS( $r )
  say $p ~~ $r;            # OUTPUT: «True␤»   (same as $r.ACCEPTS( $p )
  ```
  
  An infinite `Range` always contains any other `Range`, therefore:
  
  ```raku
  say 1..10 ~~ -∞..∞;    # OUTPUT: «True␤»
  say 1..10 ~~ -∞^..^∞;  # OUTPUT: «True␤»
  ```
  
  Similarly, a `Range` with open boundaries often includes other ranges:
  
  ```raku
  say 1..2 ~~ *..10;  # OUTPUT: «True␤»
  say 2..5 ~~ 1..*;   # OUTPUT: «True␤»
  ```
  
  It is also possible to use non-numeric ranges, for instance string based ones:
  
  ```raku
  say 'a'..'j' ~~ 'b'..'c';  # OUTPUT: «False␤»
  say 'b'..'c' ~~ 'a'..'j';  # OUTPUT: «True␤»
  say 'raku' ~~ -∞^..^∞;     # OUTPUT: «True␤»
  say 'raku' ~~ -∞..∞;       # OUTPUT: «True␤»
  say 'raku' ~~ 1..*;        # OUTPUT: «True␤»
  ```
  
  When smartmatching a `Range` of integers with a [`Cool`](/type/Cool) (string) the `ACCEPTS` methods exploits the [before](/routine/before) and [after](/routine/after) operators in order to check that the [`Cool`](/type/Cool) value is overlapping the range:
  
  ```raku
  say 1..10 ~~ '5';  # OUTPUT: «False␤»
  say '5' before 1;  # OUTPUT: «False␤»
  say '5' after 10;  # OUTPUT: «True␤»
  say '5' ~~ *..10;  # OUTPUT: «False␤»
  ```
  
  In the above example, since the `'5'` string is *after* the `10` integer value, the `Range` does not overlap with the specified value.
  
  When matching with a [`Mu`](/type/Mu) instance (i.e., a generic instance), the [cmp](/routine/cmp) operator is used.
  
  # [In Map](#___top "go to top of document")[§](#(Map)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Map#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Map:D: Positional $topic)
  multi method ACCEPTS(Map:D: Cool:D     $topic)
  multi method ACCEPTS(Map:D: Regex      $topic)
  multi method ACCEPTS(Map:D: Any        $topic)
  ```
  
  Used in smartmatching if the right-hand side is a `Map`.
  
  If the topic is list-like ([`Positional`](/type/Positional)), returns True if any of the list elements exist as a key in the Map.
  
  If the topic is of type [`Cool`](/type/Cool) (strings, integers etc.), returns True if the topic exists as a key.
  
  If the topic is a regex, returns True if any of the keys match the regex.
  
  As a fallback, the topic is coerced to a list, and the [`Positional`](/type/Positional) behavior is applied.
  
  # [In Pair](#___top "go to top of document")[§](#(Pair)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Pair#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Pair:D $: %topic)
  multi method ACCEPTS(Pair:D $: Pair:D $topic)
  multi method ACCEPTS(Pair:D $: Mu $topic)
  ```
  
  If `%topic` is an [`Associative`](/type/Associative), looks up the value using invocant's key in it and checks invocant's value `.ACCEPTS` that value:
  
  ```raku
  say %(:42a) ~~ :42a; # OUTPUT: «True␤»
  say %(:42a) ~~ :10a; # OUTPUT: «False␤»
  ```
  
  If `$topic` is another `Pair`, checks the invocant's key and value `.ACCEPTS` the `$topic`'s key and value respectively:
  
  ```raku
  say :42a ~~ :42a; # OUTPUT: «True␤»
  say :42z ~~ :42a; # OUTPUT: «False␤»
  say :10a ~~ :42a; # OUTPUT: «False␤»
  ```
  
  If `$topic` is any other value, the invocant `Pair`'s key is treated as a method name. This method is called on `$topic`, the [`Bool`](/type/Bool) result of which is compared against the invocant `Pair`'s [`Bool`](/type/Bool) value. For example, primality can be tested using smartmatch:
  
  ```raku
  say 3 ~~ :is-prime;             # OUTPUT: «True␤»
  say 3 ~~  is-prime => 'truthy'; # OUTPUT: «True␤»
  say 4 ~~ :is-prime;             # OUTPUT: «False␤»
  ```
  
  This form can also be used to check [`Bool`](/type/Bool) values of multiple methods on the same object, such as [`IO::Path`](/type/IO/Path), by using [`Junction`](/type/Junction)s:
  
  ```raku
  say "foo" .IO ~~ :f & :rw; # OUTPUT: «False␤»
  say "/tmp".IO ~~ :!f;      # OUTPUT: «True␤»
  say "."   .IO ~~ :f | :d;  # OUTPUT: «True␤»
  ```
  
  # [In Whatever](#___top "go to top of document")[§](#(Whatever)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Whatever#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Whatever:D: Mu $other)
  multi method ACCEPTS(Whatever:U: Mu $other)
  ```
  
  If the invocant is [an instance](/language/classtut#A_word_on_types), always returns `True`. If the invocant is a type object, performs a typecheck.
  
  ```raku
  say 42 ~~ (*);       # OUTPUT: «True␤»
  say 42 ~~ Whatever;  # OUTPUT: «False␤»
  ```
  
  # [In Any](#___top "go to top of document")[§](#(Any)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Any#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Any:D: Mu $other)
  ```
  
  Usage:
  
  ｢pseudo｣ without highlighting
  
  ```
  
  
  ```
  
  EXPR.ACCEPTS(EXPR);
  
  
  ```
  
  
  ```
  
  Returns `True` if `$other === self` (i.e. it checks object identity).
  
  Many built-in types override this for more specific comparisons.
  
  # [In Mu](#___top "go to top of document")[§](#(Mu)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Mu#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Mu:U: $other)
  ```
  
  `ACCEPTS` is the method that smartmatching with the [infix ~~](/routine/~~) 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).
  
  ```raku
  say 42 ~~ Mu;           # OUTPUT: «True␤»
  say 42 ~~ Int;          # OUTPUT: «True␤»
  say 42 ~~ Str;          # OUTPUT: «False␤»
  ```
  
  Note that there is no multi for defined invocants; this is to allow autothreading of [junctions](/type/Junction), which happens as a fallback mechanism when no direct candidate is available to dispatch to.
  
  # [In IO::Path](#___top "go to top of document")[§](#(IO::Path)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/IO/Path#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(IO::Path:D: Cool:D $other --> Bool:D)
  ```
  
  Coerces the argument to `IO::Path`, if necessary. Returns `True` if [`.absolute`](/routine/absolute) method on both paths returns the same string. **NOTE:** it's possible for two paths that superficially point to the same resource to NOT smartmatch as `True`, if they were constructed differently and were never fully resolved:
  
  ```raku
  say "foo/../bar".IO ~~ "bar".IO # False
  ```
  
  The reason is the two paths above may point to different resources when fully resolved (e.g. if `foo` is a symlink). Resolve the paths before smartmatching to check they point to same resource:
  
  ```raku
  say "foo/../bar".IO.resolve(:completely) ~~ "bar".IO.resolve(:completely) # True
  ```
  
  # [In Code](#___top "go to top of document")[§](#(Code)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Code#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Code:D: Mu $topic)
  ```
  
  Usually calls the code object and passes `$topic` as an argument. However, when called on a code object that takes no arguments, the code object is invoked with no arguments and `$topic` is dropped. The result of the call is returned.
  
  # [In role Numeric](#___top "go to top of document")[§](#(role_Numeric)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Numeric#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Numeric:D: $other)
  ```
  
  Returns `True` if `$other` can be coerced to `Numeric` and is [numerically equal](/routine/==, infix ⩵) to the invocant (or both evaluate to `NaN`).
  
  # [In role Setty](#___top "go to top of document")[§](#(role_Setty)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Setty#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  method ACCEPTS($other)
  ```
  
  Returns `True` if `$other` and `self` contain all the same elements, and no others.
  
  # [In Allomorph](#___top "go to top of document")[§](#(Allomorph)_method_ACCEPTS "direct link")
  
  See primary documentation
  [in context](/type/Allomorph#method_ACCEPTS)
  for **method ACCEPTS**.
  
  ```raku
  multi method ACCEPTS(Allomorph:D: Any:D \a)
  ```
  
  If the `a` parameter is [`Numeric`](/type/Numeric) (including another [allomorph](/language/glossary#Allomorph)), checks if invocant's [`Numeric`](/type/Numeric) value [ACCEPTS](/type/Numeric#method_ACCEPTS) `a`. If the `a` parameter is [`Str`](/type/Str), checks if invocant's [`Str`](/type/Str) value [ACCEPTS](/type/Str#method_ACCEPTS) `a`. If the `a` parameter is anything else, checks if both [`Numeric`](/type/Numeric) and [`Str`](/type/Str) values of the invocant `ACCEPTS` `a`.
  
  ```raku
  say "5.0" ~~ <5>; # OUTPUT: «False␤»
  say 5.0   ~~ <5>; # OUTPUT: «True␤»
  say <5.0> ~~ <5>; # OUTPUT: «True␤»
  ```
  