Skip to content

Commit

Permalink
Breaking Change: change type parameters of Either.left and Either.rig…
Browse files Browse the repository at this point in the history
…ht, closes #543
  • Loading branch information
gcanti committed Apr 18, 2019
1 parent e036cb3 commit fe6cc5c
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 165 deletions.
8 changes: 4 additions & 4 deletions src/Apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R
*
* assert.deepStrictEqual(
* ado({
* a: right<string, number>(1),
* b: right<string, boolean>(true)
* a: right(1),
* b: right(true)
* }),
* right({ a: 1, b: true })
* )
* assert.deepStrictEqual(
* ado({
* a: right<string, number>(1),
* b: left<string, number>('error')
* a: right(1),
* b: left('error')
* }),
* left('error')
* )
Expand Down
8 changes: 4 additions & 4 deletions src/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ const sequence = <F>(F: Applicative<F>) => <L, A>(ta: Either<L, HKT<F, A>>): HKT
const chainRec = <L, A, B>(a: A, f: (a: A) => Either<L, Either<A, B>>): Either<L, B> => {
return tailRec(f(a), e => {
if (e.isLeft()) {
return right(left(e.value))
return right<Either<L, B>>(left(e.value))
} else {
const r = e.value
return r.isLeft() ? left(f(r.value)) : right(right(r.value))
Expand All @@ -371,7 +371,7 @@ const chainRec = <L, A, B>(a: A, f: (a: A) => Either<L, Either<A, B>>): Either<L
*
* @since 1.0.0
*/
export const left = <L, A>(l: L): Either<L, A> => {
export const left = <L>(l: L): Either<L, never> => {
return new Left(l)
}

Expand All @@ -381,8 +381,8 @@ export const left = <L, A>(l: L): Either<L, A> => {
*
* @since 1.0.0
*/
export const right = <L, A>(a: A): Either<L, A> => {
return new Right<L, A>(a)
export const right = <A>(a: A): Either<never, A> => {
return new Right(a)
}

const of = right
Expand Down
2 changes: 1 addition & 1 deletion src/Exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ export const catchError = <A>(ma: IO<A>, handler: (e: Error) => IO<A>): IO<A> =>
* @since 1.0.0
*/
export const tryCatch = <A>(ma: IO<A>): IO<Either<Error, A>> => {
return catchError(ma.map<Either<Error, A>>(right), e => io.of(left<Error, A>(e)))
return catchError(ma.map<Either<Error, A>>(right), e => io.of(left(e)))
}
3 changes: 1 addition & 2 deletions src/TaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ export function taskify<L, R>(f: Function): () => TaskEither<L, R> {
new Task(
() =>
new Promise(resolve => {
const cbResolver = (e: L, r: R) =>
e != null ? resolve(eitherLeft<L, R>(e)) : resolve(eitherRight<L, R>(r))
const cbResolver = (e: L, r: R) => (e != null ? resolve(eitherLeft(e)) : resolve(eitherRight(r)))
f.apply(null, args.concat(cbResolver))
})
)
Expand Down
8 changes: 4 additions & 4 deletions test/Apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { catOptions, getSetoid } from '../src/Array'
import { fromEquals } from '../src/Setoid'

describe('Apply', () => {
const r1 = right<string, number>(1)
const r2 = right<string, number>(2)
const foo = left<string, number>('foo')
const bar = left<string, number>('bar')
const r1 = right(1)
const r2 = right(2)
const foo = left('foo')
const bar = left('bar')

it('applyFirst', () => {
assert.deepStrictEqual(applyFirst(option)(some(5), some(6)), some(5))
Expand Down
Loading

0 comments on commit fe6cc5c

Please sign in to comment.