@@ -1257,8 +1257,15 @@ export const modify: {
12571257 ) : ReadonlyArray . With < S , ReadonlyArray . Infer < S > | B >
12581258} = dual (
12591259 3 ,
1260- < A , B > ( self : Iterable < A > , i : number , f : ( a : A ) => B ) : Array < A | B > =>
1261- Option . getOrElse ( modifyOption ( self , i , f ) , ( ) => Array . from ( self ) )
1260+ < A , B > ( self : Iterable < A > , i : number , f : ( a : A ) => B ) : Array < A | B > => {
1261+ const out : Array < A | B > = Array . from ( self )
1262+ if ( isOutOfBounds ( i , out ) ) {
1263+ return out
1264+ }
1265+ const b = f ( out [ i ] as A )
1266+ out [ i ] = b
1267+ return out
1268+ }
12621269)
12631270
12641271/**
@@ -1291,11 +1298,11 @@ export const modifyOption: {
12911298 f : ( a : ReadonlyArray . Infer < S > ) => B
12921299 ) : Option . Option < ReadonlyArray . With < S , ReadonlyArray . Infer < S > | B > >
12931300} = dual ( 3 , < A , B > ( self : Iterable < A > , i : number , f : ( a : A ) => B ) : Option . Option < Array < A | B > > => {
1294- const arr = Array . from ( self )
1301+ const arr = fromIterable ( self )
12951302 if ( isOutOfBounds ( i , arr ) ) {
12961303 return Option . none ( )
12971304 }
1298- const out : Array < A | B > = arr
1305+ const out : Array < A | B > = Array . isArray ( self ) ? self . slice ( ) : arr
12991306 const b = f ( arr [ i ] )
13001307 out [ i ] = b
13011308 return Option . some ( out )
@@ -1332,6 +1339,38 @@ export const remove: {
13321339 return out
13331340} )
13341341
1342+ /**
1343+ * Delete the element at the specified index, creating a new `Array`,
1344+ * or return `None` if the index is out of bounds.
1345+ *
1346+ * @example
1347+ * ```ts
1348+ * import * as assert from "node:assert"
1349+ * import { Array, Option } from "effect"
1350+ *
1351+ * const numbers = [1, 2, 3, 4]
1352+ * const result = Array.removeOption(numbers, 2)
1353+ * assert.deepStrictEqual(result, Option.some([1, 2, 4]))
1354+ *
1355+ * const outOfBoundsResult = Array.removeOption(numbers, 5)
1356+ * assert.deepStrictEqual(outOfBoundsResult, Option.none())
1357+ * ```
1358+ *
1359+ * @since 3.16.0
1360+ */
1361+ export const removeOption : {
1362+ ( i : number ) : < A > ( self : Iterable < A > ) => Option . Option < Array < A > >
1363+ < A > ( self : Iterable < A > , i : number ) : Option . Option < Array < A > >
1364+ } = dual ( 2 , < A > ( self : Iterable < A > , i : number ) : Option . Option < Array < A > > => {
1365+ const arr = fromIterable ( self )
1366+ if ( isOutOfBounds ( i , arr ) ) {
1367+ return Option . none ( )
1368+ }
1369+ const out = Array . isArray ( self ) ? self . slice ( ) : arr
1370+ out . splice ( i , 1 )
1371+ return Option . some ( out )
1372+ } )
1373+
13351374/**
13361375 * Reverse an `Iterable`, creating a new `Array`.
13371376 *
0 commit comments