diff --git a/packages/effect-fc/src/types/SubscriptionSubRef.ts b/packages/effect-fc/src/types/SubscriptionSubRef.ts index b66dc99..1abeaac 100644 --- a/packages/effect-fc/src/types/SubscriptionSubRef.ts +++ b/packages/effect-fc/src/types/SubscriptionSubRef.ts @@ -157,3 +157,30 @@ export const makeFromChunkFindFirst: { index => Chunk.replace(parentValue, index, value), )), ) as any + +export const makeFromChunkFindLast: { + >>( + parent: B, + findLastPredicate: Predicate.Predicate extends Chunk.NonEmptyChunk ? A : never>, + ): SubscriptionSubRef< + Effect.Effect.Success extends Chunk.NonEmptyChunk ? A : never, + B + > + >>( + parent: B, + findLastPredicate: Predicate.Predicate extends Chunk.Chunk ? A : never>, + ): SubscriptionSubRef< + Effect.Effect.Success extends Chunk.Chunk ? A : never, + B + > +} = ( + parent: SubscriptionRef.SubscriptionRef>, + findLastPredicate: Predicate.Predicate.Any, +) => new SubscriptionSubRefImpl( + parent, + parentValue => Option.getOrThrow(Chunk.findLast(parentValue, findLastPredicate)), + (parentValue, value) => Option.getOrThrow(Option.andThen( + Chunk.findLastIndex(parentValue, findLastPredicate), + index => Chunk.replace(parentValue, index, value), + )), +) as any