From 63731f1628401040d3afc6068610e1a0a8a3d1c5 Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Fri, 7 Jun 2024 16:04:49 +0200 Subject: [PATCH] Add `lastNonEmpty` function to `Chunk` module, closes #2946 (#2951) --- .changeset/sour-waves-call.md | 5 +++++ packages/effect/src/Chunk.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/sour-waves-call.md diff --git a/.changeset/sour-waves-call.md b/.changeset/sour-waves-call.md new file mode 100644 index 0000000000..f03637f0c8 --- /dev/null +++ b/.changeset/sour-waves-call.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +Add `lastNonEmpty` function to `Chunk` module, closes #2946 diff --git a/packages/effect/src/Chunk.ts b/packages/effect/src/Chunk.ts index 4e3aa3cb32..ab7ddffab3 100644 --- a/packages/effect/src/Chunk.ts +++ b/packages/effect/src/Chunk.ts @@ -819,6 +819,8 @@ export const head: (self: Chunk) => Option = get(0) /** * Returns the first element of this chunk. * + * It will throw an error if the chunk is empty. + * * @since 2.0.0 * @category unsafe */ @@ -843,11 +845,21 @@ export const last = (self: Chunk): Option => get(self, self.length - 1) /** * Returns the last element of this chunk. * + * It will throw an error if the chunk is empty. + * * @since 2.0.0 * @category unsafe */ export const unsafeLast = (self: Chunk): A => unsafeGet(self, self.length - 1) +/** + * Returns the last element of this non empty chunk. + * + * @since 3.4.0 + * @category elements + */ +export const lastNonEmpty: (self: NonEmptyChunk) => A = unsafeLast + /** * @since 2.0.0 */