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 */