@fakenickels/let-anything
Advanced tools
Comparing version 0.1.0 to 1.0.0
{ | ||
"name": "@fakenickels/let-anything", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"main": "src/index.js", | ||
"license": "MIT", | ||
"typings": "src/index.ts", | ||
"typings": "src/index.d.ts", | ||
"devDependencies": { | ||
"fp-ts": "^2.8.2", | ||
"typescript": "^4.0.3" | ||
}, | ||
"scripts": { | ||
"build": "tsc --declaration" | ||
} | ||
} |
@@ -6,3 +6,8 @@ type Config<T> = { | ||
export function letAnything<T>(config: Config<T>) { | ||
return (gen: () => Generator<T>) => { | ||
interface LetAnything { | ||
(gen: () => Generator<T, any, any>): T; | ||
<TNext>(gen: () => Generator<T, any, TNext>): T; | ||
} | ||
const lettified: LetAnything = (gen: () => Generator<T, any, any>) => { | ||
const context = gen() | ||
@@ -12,6 +17,8 @@ | ||
? step.value | ||
: config.let_(step.value, value => compose(context.next(value))) | ||
: config.let_(step.value, value => compose(context.next(value as any))) // TODO: remove any | ||
return compose(context.next()) | ||
} | ||
return lettified | ||
} |
@@ -8,3 +8,3 @@ import {either} from 'fp-ts' | ||
function* stuff() { | ||
const stuff = letEither<string>(function*() { | ||
const value = yield either.right("d"); | ||
@@ -15,7 +15,7 @@ const anotherValue = yield either.right("e"); | ||
return either.right(value + anotherValue + anotherAnother); | ||
} | ||
}) | ||
console.log( | ||
either.getOrElse(error => `Something went wrong: ${error}`)(letEither(stuff)) | ||
either.getOrElse(error => `Something went wrong: ${error}`)(stuff) | ||
) |
@@ -97,3 +97,3 @@ "use strict"; | ||
}); | ||
function stuff() { | ||
letResultAsync(function () { | ||
var value, anotherValue, anotherAnother; | ||
@@ -111,6 +111,5 @@ return __generator(this, function (_a) { | ||
anotherAnother = _a.sent(); | ||
return [2 /*return*/, Promise.resolve(new Ok(value + anotherValue + anotherAnother))]; | ||
return [2 /*return*/, new Ok(value + anotherValue + anotherAnother)]; | ||
} | ||
}); | ||
} | ||
letResultAsync(stuff); | ||
}); |
@@ -7,3 +7,3 @@ { | ||
"lib": ["ES2018", "DOM"], | ||
"rootDirs": [ "./src", "./tests" ], | ||
"rootDirs": ["./src", "./tests"], | ||
"strict": true, | ||
@@ -10,0 +10,0 @@ "noImplicitAny": true, |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20008
271
1