@abadi199/maybe
Advanced tools
Comparing version
@@ -27,2 +27,5 @@ "use strict"; | ||
}; | ||
Nothing.prototype.do = function (_f) { | ||
return this; | ||
}; | ||
return Nothing; | ||
@@ -55,2 +58,8 @@ }()); | ||
}; | ||
Just.prototype.do = function (f) { | ||
if (this.value) { | ||
f(this.value); | ||
} | ||
return this; | ||
}; | ||
return Just; | ||
@@ -60,4 +69,8 @@ }()); | ||
function just(value) { | ||
return new Just(value); | ||
return value ? new Just(value) : nothing(); | ||
} | ||
exports.just = just; | ||
function maybe(value) { | ||
return just(value); | ||
} | ||
exports.maybe = maybe; |
{ | ||
"name": "@abadi199/maybe", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A DataType Representing the concept of null in more safer way.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,2 +13,3 @@ export enum MaybeKind { | ||
withDefault(payload: data): data; | ||
do(f: (payload: data) => void): Maybe<data>; | ||
} | ||
@@ -33,2 +34,5 @@ | ||
} | ||
do(_f: (payload: data) => void): Maybe<data> { | ||
return this; | ||
} | ||
} | ||
@@ -57,2 +61,8 @@ | ||
} | ||
do(f: (payload: data) => void): Maybe<data> { | ||
if (this.value) { | ||
f(this.value); | ||
} | ||
return this; | ||
} | ||
@@ -66,2 +76,6 @@ constructor(public value: data) {} | ||
export function maybe<data>(value: data): Maybe<data> { | ||
return just(value); | ||
} | ||
export type Maybe<data> = Nothing<data> | Just<data>; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10188
6.37%197
15.2%1
Infinity%