-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: library rewritten using classes to boost performance improve signatures.
- Loading branch information
1 parent
a2f57bf
commit c27939f
Showing
58 changed files
with
616 additions
and
588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
exclude_patterns: | ||
- "**/*.spec.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
"typings": "index.d.ts", | ||
"sideEffects": false, | ||
"author": "Patrick Michalina <[email protected]> (https://patrickmichalina.com)", | ||
"contributors": [ | ||
"Williama Reynolds" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
|
@@ -35,27 +38,27 @@ | |
}, | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^3.1.1", | ||
"@types/fs-extra": "^8.1.0", | ||
"@types/jest": "^25.2.1", | ||
"@types/fs-extra": "^9.0.0", | ||
"@types/jest": "^25.2.2", | ||
"@types/node": "^14.0.1", | ||
"codecov": "^3.6.5", | ||
"fast-check": "^1.24.2", | ||
"fs-extra": "^9.0.0", | ||
"istanbul": "^0.4.5", | ||
"jest": "26.0.1", | ||
"jest-junit": "^10.0.0", | ||
"rollup": "^2.10.0", | ||
"rollup": "^2.10.2", | ||
"rxjs": "^6.5.4", | ||
"semantic-release": "^17.0.7", | ||
"terser": "^4.6.13", | ||
"ts-jest": "^25.5.1", | ||
"ts-jest": "^26.0.0", | ||
"ts-node": "^8.10.1", | ||
"tslint": "^6.1.2", | ||
"tslint-immutable": "^6.0.1", | ||
"typescript": "^3.9.2" | ||
}, | ||
"peerDependencies": { | ||
"tslib": "^1.12.0", | ||
"tslib": "^2.0.0", | ||
"rxjs": "^6.5" | ||
}, | ||
"jest": { | ||
|
@@ -70,7 +73,7 @@ | |
"coverageThreshold": { | ||
"global": { | ||
"branches": 100, | ||
"functions": 95, | ||
"functions": 100, | ||
"lines": 100, | ||
"statements": 100 | ||
} | ||
|
@@ -80,7 +83,8 @@ | |
}, | ||
"testPathIgnorePatterns": [ | ||
"/node_modules/", | ||
"/dist/" | ||
"/dist/", | ||
"public_api.ts" | ||
], | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(ts?)$", | ||
"moduleFileExtensions": [ | ||
|
@@ -92,4 +96,4 @@ | |
"node" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Either } from './either' | ||
|
||
export function either<L, R>(left?: L, right?: R) { | ||
return new Either(left, right) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { IEitherPattern, IEither } from './either.interface' | ||
|
||
export class Either<L, R> implements IEither<L, R> { | ||
constructor(private readonly left?: L, private readonly right?: R) { | ||
if (this.neitherExist()) { | ||
throw new TypeError('Either requires a left or a right') | ||
} | ||
if (this.bothExist()) { | ||
throw new TypeError('Either cannot have both a left and a right') | ||
} | ||
} | ||
|
||
private static exists<T>(value?: T): boolean { | ||
return typeof value !== 'undefined' && value !== null | ||
} | ||
|
||
private bothExist(): boolean { | ||
return this.isLeft() && this.isRight() | ||
} | ||
|
||
private neitherExist(): boolean { | ||
return !this.isLeft() && !this.isRight() | ||
} | ||
|
||
public isLeft(): boolean { | ||
return Either.exists(this.left) | ||
} | ||
|
||
public isRight(): boolean { | ||
return Either.exists(this.right) | ||
} | ||
|
||
public match<T>(pattern: IEitherPattern<L, R, T>): T { | ||
return this.isRight() | ||
? pattern.right(this.right as R) | ||
: pattern.left(this.left as L) | ||
} | ||
|
||
public tap<T>(pattern: Partial<IEitherPattern<L, R, T>>): void { | ||
this.isRight() | ||
? typeof pattern.right === 'function' && pattern.right(this.right as R) | ||
: typeof pattern.left === 'function' && pattern.left(this.left as L) | ||
} | ||
|
||
public map<T>(fn: (r: R) => T): IEither<L, T> { | ||
return this.isRight() | ||
? new Either<L, T>(undefined, fn(this.right as R)) | ||
: new Either<L, T>(this.left) | ||
} | ||
|
||
public flatMap<T>(fn: (r: R) => IEither<L, T>): IEither<L, T> { | ||
return this.isRight() | ||
? fn(this.right as R) | ||
: new Either<L, T>(this.left) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './either' | ||
export * from './either.factory' | ||
export * from './either.interface' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { maybe, Maybe, either, Either, ok, fail, Result, reader, Reader } from './index' | ||
|
||
describe('package api', () => { | ||
it('should export maybe', () => { | ||
expect(maybe(1)).toBeInstanceOf(Maybe) | ||
}) | ||
|
||
it('should export either', () => { | ||
expect(either(1)).toBeInstanceOf(Either) | ||
}) | ||
|
||
it('should export result', () => { | ||
expect(ok(1)).toBeInstanceOf(Result) | ||
expect(fail(1)).toBeInstanceOf(Result) | ||
}) | ||
|
||
it('should export reader', () => { | ||
expect(reader(_cfg => 1)).toBeInstanceOf(Reader) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './monads/index' | ||
export * from './interfaces/index' | ||
export { | ||
maybeToObservable | ||
} from './util/index' | ||
export * from './maybe/public_api' | ||
export * from './reader/public_api' | ||
export * from './either/public_api' | ||
export * from './result/public_api' | ||
export * from './monad/public_api' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { maybe, none, some } from './maybe.factory' | ||
|
||
describe('should construct maybes', () => { | ||
it('should handle "maybe" case', () => { | ||
const sut = 'asdasd' as string | undefined | ||
expect(maybe(sut).isSome()).toEqual(true) | ||
}) | ||
|
||
it('should handle "none" case', () => { | ||
expect(none().isNone()).toEqual(true) | ||
}) | ||
|
||
it('should handle "some" case', () => { | ||
expect(some('test').isSome()).toEqual(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Maybe } from './maybe' | ||
|
||
export function maybe<T>(value?: T) { | ||
return new Maybe<T>(value) | ||
} | ||
|
||
export function none<T>() { | ||
return Maybe.none<T>() | ||
} | ||
|
||
export function some<T>(value: T) { | ||
return maybe(value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.