Hyperlinkv0.8.0-beta.28

Chunk

Chunk.dropconsteffect/Chunk.ts:799
(n: number): <A>(self: Chunk<A>) => Chunk<A>
<A>(self: Chunk<A>, n: number): Chunk<A>

Drops the first up to n elements from the chunk.

Example (Dropping elements from the start)

import { Chunk } from "effect"

const chunk = Chunk.make(1, 2, 3, 4, 5)
const result = Chunk.drop(chunk, 2)
console.log(Chunk.toArray(result)) // [3, 4, 5]
elements
Source effect/Chunk.ts:79939 lines
export const drop: {
  (n: number): <A>(self: Chunk<A>) => Chunk<A>
  <A>(self: Chunk<A>, n: number): Chunk<A>
} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => {
  if (n <= 0) {
    return self
  } else if (n >= self.length) {
    return _empty
  } else {
    switch (self.backing._tag) {
      case "ISlice": {
        return makeChunk({
          _tag: "ISlice",
          chunk: self.backing.chunk,
          offset: self.backing.offset + n,
          length: self.backing.length - n
        })
      }
      case "IConcat": {
        if (n > self.left.length) {
          return drop(self.right, n - self.left.length)
        }
        return makeChunk({
          _tag: "IConcat",
          left: drop(self.left, n),
          right: self.right
        })
      }
      default: {
        return makeChunk({
          _tag: "ISlice",
          chunk: self,
          offset: n,
          length: self.length - n
        })
      }
    }
  }
})
Referenced by 12 symbols