Skip to content

Commit

Permalink
Add lastNonEmpty function to Chunk module, closes #2946 (#2951)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and mikearnaldi committed Jun 10, 2024
1 parent 98ecc5b commit 55298b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-waves-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add `lastNonEmpty` function to `Chunk` module, closes #2946
12 changes: 12 additions & 0 deletions packages/effect/src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ export const head: <A>(self: Chunk<A>) => Option<A> = 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
*/
Expand All @@ -843,11 +845,21 @@ export const last = <A>(self: Chunk<A>): Option<A> => 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 = <A>(self: Chunk<A>): A => unsafeGet(self, self.length - 1)

/**
* Returns the last element of this non empty chunk.
*
* @since 3.4.0
* @category elements
*/
export const lastNonEmpty: <A>(self: NonEmptyChunk<A>) => A = unsafeLast

/**
* @since 2.0.0
*/
Expand Down

0 comments on commit 55298b7

Please sign in to comment.