Skip to content

Commit

Permalink
replace instanceof checks with valued _tags, fix #96 (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored May 24, 2017
1 parent 96dbdf7 commit 969e5ae
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
**Note**: Gaps between patch versions are faulty/broken releases.
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

# 0.2.9

- **New Feature**
- add Monoidal type class (@gcanti)
- **Bug Fix**
- fix `foldMap`, closes #89 (@gcanti)
- replace `instanceof` checks with valued `_tag`s, fix #96 (@gcanti, @sledorze)

# 0.2.8

- **New Feature**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fp-ts",
"version": "0.2.8",
"version": "0.2.9",
"description": "Functional programming in TypeScript",
"files": [
"lib",
Expand Down
8 changes: 4 additions & 4 deletions src/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Left<L, A> implements
FantasyBifunctor<URI, L, A> {

static of = of
readonly _tag: 'Left'
readonly _tag = 'Left'
readonly _L: L
readonly _A: A
readonly _URI: URI
Expand Down Expand Up @@ -101,7 +101,7 @@ export class Right<L, A> implements
FantasyBifunctor<URI, L, A> {

static of = of
readonly _tag: 'Right'
readonly _tag = 'Right'
readonly _L: L
readonly _A: A
readonly _URI: URI
Expand Down Expand Up @@ -222,11 +222,11 @@ export function chainRec<L, A, B>(f: (a: A) => Either<L, Either<A, B>>, a: A): E
}

export function isLeft<L, A>(fa: Either<L, A>): fa is Left<L, A> {
return fa instanceof Left
return fa._tag === 'Left'
}

export function isRight<L, A>(fa: Either<L, A>): fa is Right<L, A> {
return fa instanceof Right
return fa._tag === 'Right'
}

export function left<L, A>(l: L): Either<L, A> {
Expand Down
6 changes: 3 additions & 3 deletions src/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class None<A> implements
static empty = empty
static zero = zero
static value: Option<any> = new None()
readonly _tag: 'None'
readonly _tag = 'None'
readonly _A: A
readonly _URI: URI
constructor() {
Expand Down Expand Up @@ -114,7 +114,7 @@ export class Some<A> implements
static of = of
static empty = empty
static zero = zero
readonly _tag: 'Some'
readonly _tag = 'Some'
readonly _A: A
readonly _URI: URI
constructor(public readonly value: A) {}
Expand Down Expand Up @@ -238,7 +238,7 @@ export function getStaticMonoid<A>(semigroup: StaticSemigroup<A>): StaticMonoid<
}

export function isSome<A>(fa: Option<A>): fa is Some<A> {
return fa instanceof Some
return fa._tag === 'Some'
}

export function isNone<A>(fa: Option<A>): fa is None<A> {
Expand Down
12 changes: 6 additions & 6 deletions src/These.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type These<L, A> = This<L, A> | That<L, A> | Both<L, A>

export class This<L, A> {
static of = of
readonly _tag: 'This'
readonly _tag = 'This'
readonly _L: L
readonly _A: A
readonly _URI: URI
Expand Down Expand Up @@ -75,7 +75,7 @@ export class This<L, A> {

export class That<L, A> {
static of = of
readonly _tag: 'That'
readonly _tag = 'That'
readonly _L: L
readonly _A: A
readonly _URI: URI
Expand Down Expand Up @@ -125,7 +125,7 @@ export class That<L, A> {

export class Both<L, A> {
static of = of
readonly _tag: 'This'
readonly _tag = 'Both'
readonly _L: L
readonly _A: A
readonly _URI: URI
Expand Down Expand Up @@ -219,15 +219,15 @@ export function traverse<F extends HKTS>(applicative: StaticApplicative<F>): <L,
}

export function isThis<L, A>(fa: These<L, A>): fa is This<L, A> {
return fa instanceof This
return fa._tag === 'This'
}

export function isThat<L, A>(fa: These<L, A>): fa is That<L, A> {
return fa instanceof That
return fa._tag === 'That'
}

export function isBoth<L, A>(fa: These<L, A>): fa is Both<L, A> {
return fa instanceof Both
return fa._tag === 'Both'
}

export function this_<L, A>(l: L): These<L, A> {
Expand Down
8 changes: 4 additions & 4 deletions src/Validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Failure<L, A> implements
FantasyAlt<URI, A> {

static of = of
readonly _tag: 'Failure'
readonly _tag = 'Failure'
readonly _L: L
readonly _A: A
readonly _URI: URI
Expand Down Expand Up @@ -109,7 +109,7 @@ export class Success<L, A> implements
FantasyAlt<URI, A> {

static of = of
readonly _tag: 'Success'
readonly _tag = 'Success'
readonly _L: L
readonly _A: A
readonly _URI: URI
Expand Down Expand Up @@ -220,11 +220,11 @@ export function traverse<F extends HKTS>(applicative: StaticApplicative<F>): <L,
}

export function isFailure<L, A>(fa: Validation<L, A>): fa is Failure<L, A> {
return fa instanceof Failure
return fa._tag === 'Failure'
}

export function isSuccess<L, A>(fa: Validation<L, A>): fa is Success<L, A> {
return fa instanceof Success
return fa._tag === 'Success'
}

export function failure<L, A>(semigroup: StaticSemigroup<L>, l: L): Validation<L, A> {
Expand Down

0 comments on commit 969e5ae

Please sign in to comment.