Hyperlinkv0.8.0-beta.28

Array

Array.takeRightconsteffect/Array.ts:1329
(n: number): <A>(self: Iterable<A>) => Array<A>
<A>(self: Iterable<A>, n: number): Array<A>

Keeps the last n elements, creating a new array.

When to use

Use to keep the last n elements of an iterable.

Details

n is clamped to [0, length]. Returns an empty array when n <= 0.

Example (Taking from the end)

import { Array } from "effect"

console.log(Array.takeRight([1, 2, 3, 4, 5], 3)) // [3, 4, 5]
Source effect/Array.ts:13298 lines
export const takeRight: {
  (n: number): <A>(self: Iterable<A>) => Array<A>
  <A>(self: Iterable<A>, n: number): Array<A>
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
  const input = fromIterable(self)
  const i = clamp(n, input)
  return i === 0 ? [] : input.slice(-i)
})