txt: ## head.md
  head
  
  Combined from primary sources listed below.
  
  # [In List](#___top "go to top of document")[§](#(List)_method_head "direct link")
  
  See primary documentation
  [in context](/type/List#method_head)
  for **method head**.
  
  ```raku
  multi method head(Any:D:) is raw
  multi method head(Any:D: Callable:D $w)
  multi method head(Any:D: $n)
  ```
  
  This method is directly inherited from [`Any`](/type/Any), and it returns the **first** `$n` items of the list, an empty list if `$n` <= 0, or the first element with no argument. The version that takes a [`Callable`](/type/Callable) uses a [`WhateverCode`](/type/WhateverCode) to specify all elements, starting from the first, but the last ones.
  
  Examples:
  
  ```raku
  say <a b c d e>.head ;     # OUTPUT: «a␤»
  say <a b c d e>.head(2);   # OUTPUT: «(a b)␤»
  say <a b c d e>.head(*-3); # OUTPUT: «(a b)␤»
  ```
  
  # [In Any](#___top "go to top of document")[§](#(Any)_routine_head "direct link")
  
  See primary documentation
  [in context](/type/Any#routine_head)
  for **routine head**.
  
  ```raku
  multi method head(Any:D:) is raw
  multi method head(Any:D: Callable:D $w)
  multi method head(Any:D: $n)
  ```
  
  Returns either the first element in the object, or the first `$n` if that's used.
  
  ```raku
  "aaabbc".comb.head.put; # OUTPUT: «a␤»
  say ^10 .head(5);           # OUTPUT: «(0 1 2 3 4)␤»
  say ^∞ .head(5);            # OUTPUT: «(0 1 2 3 4)␤»
  say ^10 .head;              # OUTPUT: «0␤»
  say ^∞ .head;               # OUTPUT: «0␤»
  ```
  
  In the first two cases, the results are different since there's no defined order in [`Mix`](/type/Mix)es. In the other cases, it returns a [`Seq`](/type/Seq). A [`Callable`](/type/Callable) can be used to return all but the last elements:
  
  ```raku
  say (^10).head( * - 3 );# OUTPUT: «(0 1 2 3 4 5 6)␤»
  ```
  
  As of release 2022.07 of the Rakudo compiler, there is also a "sub" version of `head`.
  
  ```raku
  multi head(\specifier, +values)
  ```
  
  It **must** have the head specifier as the first argument. The rest of the arguments are turned into a [`Seq`](/type/Seq) and then have the `head` method called on it.
  
  # [In Supply](#___top "go to top of document")[§](#(Supply)_method_head "direct link")
  
  See primary documentation
  [in context](/type/Supply#method_head)
  for **method head**.
  
  ```raku
  multi method head(Supply:D:)
  multi method head(Supply:D: Callable:D $limit)
  multi method head(Supply:D: \limit)
  ```
  
  Creates a "head" supply with the same semantics as [List.head](/type/List#method_head).
  
  ```raku
  my $s = Supply.from-list(4, 10, 3, 2);
  my $hs = $s.head(2);
  $hs.tap(&say);           # OUTPUT: «4␤10␤»
  ```
  
  Since release 2020.07, A [`WhateverCode`](/type/WhateverCode) can be used also, again with the same semantics as `List.head`
  
  ```raku
  my $s = Supply.from-list(4, 10, 3, 2, 1);
  my $hs = $s.head( * - 2);
  $hs.tap(&say);           # OUTPUT: «4␤10␤3␤»
  ```
  