nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gcanti/fp-ts
Pull request #824 (2019-04-12 09:33:12)

Add get or else to task either
Add `getOrElse` to `TaskEither`.


Patch:
diff --git a/docs/modules/TaskEither.ts.md b/docs/modules/TaskEither.ts.md
index b3f3d7e4..f59027e3 100644
--- a/docs/modules/TaskEither.ts.md
+++ b/docs/modules/TaskEither.ts.md
@@ -27,6 +27,8 @@ error of type `L`. If you want to represent an asynchronous computation that nev
   - [fold (method)](#fold-method)
   - [foldTask (method)](#foldtask-method)
   - [foldTaskEither (method)](#foldtaskeither-method)
+  - [getOrElse (method)](#getorelse-method)
+  - [getOrElseL (method)](#getorelsel-method)
   - [mapLeft (method)](#mapleft-method)
   - [orElse (method)](#orelse-method)
   - [alt (method)](#alt-method)
@@ -198,6 +200,28 @@ foldTaskEither<M, B>(onLeft: (l: L) => TaskEither<M, B>, onRight: (a: A) => Task
 
 Added in v1.10.0
 
+## getOrElse (method)
+
+Similar to `fold`, return the value from Right or the given argument if Left.
+
+**Signature**
+
+```ts
+getOrElse(a: A): Task<A> { ... }
+```
+
+Added in v1.17.0
+
+## getOrElseL (method)
+
+**Signature**
+
+```ts
+getOrElseL(f: (l: L) => A): Task<A> { ... }
+```
+
+Added in v1.17.0
+
 ## mapLeft (method)
 
 **Signature**
diff --git a/src/TaskEither.ts b/src/TaskEither.ts
index 982616e8..5235181c 100644
--- a/src/TaskEither.ts
+++ b/src/TaskEither.ts
@@ -13,7 +13,7 @@ import {
   right as eitherRight
 } from './Either'
 import * as eitherT from './EitherT'
-import { constant, constIdentity, Lazy, Predicate, Refinement } from './function'
+import { constant, constIdentity, Lazy, Predicate, Refinement, identity } from './function'
 import { IO } from './IO'
 import { IOEither } from './IOEither'
 import { Monad2 } from './Monad'
@@ -109,6 +109,19 @@ export class TaskEither<L, A> {
   foldTaskEither<M, B>(onLeft: (l: L) => TaskEither<M, B>, onRight: (a: A) => TaskEither<M, B>): TaskEither<M, B> {
     return new TaskEither(this.value.chain(e => e.fold(onLeft, onRight).value))
   }
+  /**
+   * Similar to `fold`, return the value from Right or the given argument if Left.
+   * @since 1.17.0
+   */
+  getOrElse(a: A): Task<A> {
+    return this.getOrElseL(() => a)
+  }
+  /**
+   * @since 1.17.0
+   */
+  getOrElseL(f: (l: L) => A): Task<A> {
+    return this.fold(f, identity)
+  }
   mapLeft<M>(f: (l: L) => M): TaskEither<M, A> {
     return new TaskEither(this.value.map(e => e.mapLeft(f)))
   }


Test patch:
diff --git a/test/TaskEither.ts b/test/TaskEither.ts
index fd57c90f..f8c1b1ee 100644
--- a/test/TaskEither.ts
+++ b/test/TaskEither.ts
@@ -172,6 +172,16 @@ describe('TaskEither', () => {
     })
   })
 
+  it('getOrElse', () => {
+    const v: number = 42
+    const te1 = taskEither.of<string, number>(1).getOrElse(v)
+    const te2 = fromLeft<string, number>('foo').getOrElse(v)
+    return Promise.all([te1.run(), te2.run()]).then(([b1, b2]) => {
+      assert.strictEqual(b1, 1)
+      assert.strictEqual(b2, 42)
+    })
+  })
+
   it('bimap', () => {
     const f = (s: string): number => s.length
     const g = (n: number): boolean => n > 2
Repository: gcanti/fp-ts
Pull request #834 (2019-04-16 06:32:43)

New Feature: add NonEmptyArray2v.copy


Patch:
diff --git a/src/Array.ts b/src/Array.ts
index 1eb83511..187b647b 100644
--- a/src/Array.ts
+++ b/src/Array.ts
@@ -875,7 +875,6 @@ export const refine = <A, B extends A>(as: Array<A>, refinement: Refinement<A, B
 }
 
 /**
- *
  * @since 1.0.0
  */
 export const copy = <A>(as: Array<A>): Array<A> => {
diff --git a/src/NonEmptyArray2v.ts b/src/NonEmptyArray2v.ts
index 79a023fb..43061536 100644
--- a/src/NonEmptyArray2v.ts
+++ b/src/NonEmptyArray2v.ts
@@ -265,6 +265,13 @@ export function modifyAt<A>(nea: NonEmptyArray<A>, i: number, f: (a: A) => A): O
   return A.modifyAt(nea, i, f) as any
 }
 
+/**
+ * @since 1.17.0
+ */
+export const copy = <A>(nea: NonEmptyArray<A>): NonEmptyArray<A> => {
+  return A.copy(nea) as any
+}
+
 /**
  * @since 1.15.0
  */


Test patch:
diff --git a/test/NonEmptyArray2v.ts b/test/NonEmptyArray2v.ts
index 3af766d0..dcf0384b 100644
--- a/test/NonEmptyArray2v.ts
+++ b/test/NonEmptyArray2v.ts
@@ -26,7 +26,8 @@ import {
   fromNonEmptyArray,
   cons,
   snoc,
-  modifyAt
+  modifyAt,
+  copy
 } from '../src/NonEmptyArray2v'
 import { none, option, some, isSome } from '../src/Option'
 import { ordNumber } from '../src/Ord'
@@ -311,6 +312,13 @@ describe.only('NonEmptyArray2v', () => {
     assert.deepStrictEqual(modifyAt(make<number>(1, [2]), 1, double), some(make(1, [4])))
   })
 
+  it('copy', () => {
+    const nea1 = make<number>(1, [])
+    const nea2 = copy(nea1)
+    assert.deepStrictEqual(nea2, nea1)
+    assert.strictEqual(nea2 === nea1, false)
+  })
+
   it('filter', () => {
     const make2 = (x: number) => ({ x })
     const a1 = make2(1)