# encoding: ascii
# api: powershell
# title: Skip-Object
# description: Skip -every 3rd, or -upto 3 at a time, or the -first 3, or the -last 3 or any combination of the above …
# version: 0.1
# type: function
# license: CC0
# function: Skip-Object
# x-poshcode-id: 1749
# x-archived: 2010-04-11T23:18:24
#
#
function Skip-Object {
param( 
   [int]$First = 0
, 
   [int]$Last = 0
,
   [int]$Every = 0
,
   [int]$UpTo = 0
)
begin {
   if($Last) {
      $Queue = new-object System.Collections.Queue $Last
   }
   $e = $every
   $UpTo++
   # $u = $UpTo
}
process {
   $_ | 
   where { 
      --$First -lt 0 
   } | 
   foreach {
      if($Last) {
         $Queue.EnQueue($_)
         if($Queue.Count -gt $Last) {
            $Queue.DeQueue()
         }
      } else { $_ }
   } |
   foreach { 
      if(!$UpTo) {
         $_
      } elseif( --$u -le 0) { 
         $_; $U = $UpTo
      }
   } |
   foreach { 
      if($every -and (--$e -le 0)) { 
         $e = $every 
      } else { $_ } 
   }
}
}
