fp-ts-contrib
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -16,2 +16,7 @@ # Changelog | ||
# 0.1.5 | ||
- **New Feature** | ||
- add some combinators to `TaskOption`, #24 (@bwlt) | ||
# 0.1.4 | ||
@@ -18,0 +23,0 @@ |
@@ -6,2 +6,4 @@ import { Alt1 } from 'fp-ts/lib/Alt'; | ||
import { TaskEither } from 'fp-ts/lib/TaskEither'; | ||
import { Lazy } from 'fp-ts/lib/function'; | ||
import { Filterable1 } from 'fp-ts/lib/Filterable'; | ||
declare module 'fp-ts/lib/HKT' { | ||
@@ -74,6 +76,20 @@ interface URItoKind<A> { | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
export declare function mapNullable<A, B>(f: (a: A) => B | null | undefined): (ma: TaskOption<A>) => TaskOption<B>; | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
export declare function tryCatch<A>(f: Lazy<Promise<A>>): TaskOption<A>; | ||
/** | ||
* @since 0.1.0 | ||
*/ | ||
export declare const taskOption: Monad1<URI> & Alt1<URI>; | ||
declare const alt: <A>(that: () => TaskOption<A>) => (fa: TaskOption<A>) => TaskOption<A>, ap: <A>(fa: TaskOption<A>) => <B>(fab: TaskOption<(a: A) => B>) => TaskOption<B>, apFirst: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<A>, apSecond: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<B>, chain: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<B>, chainFirst: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<A>, flatten: <A>(mma: TaskOption<TaskOption<A>>) => TaskOption<A>, map: <A, B>(f: (a: A) => B) => (fa: TaskOption<A>) => TaskOption<B>; | ||
export declare const taskOption: Monad1<URI> & Alt1<URI> & Filterable1<URI>; | ||
declare const alt: <A>(that: () => TaskOption<A>) => (fa: TaskOption<A>) => TaskOption<A>, ap: <A>(fa: TaskOption<A>) => <B>(fab: TaskOption<(a: A) => B>) => TaskOption<B>, apFirst: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<A>, apSecond: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<B>, chain: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<B>, chainFirst: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<A>, flatten: <A>(mma: TaskOption<TaskOption<A>>) => TaskOption<A>, map: <A, B>(f: (a: A) => B) => (fa: TaskOption<A>) => TaskOption<B>, partition: { | ||
<A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>): (fa: TaskOption<A>) => import("fp-ts/lib/Compactable").Separated<TaskOption<A>, TaskOption<B>>; | ||
<A>(predicate: import("fp-ts/lib/function").Predicate<A>): (fa: TaskOption<A>) => import("fp-ts/lib/Compactable").Separated<TaskOption<A>, TaskOption<A>>; | ||
}, partitionMap: <A, B, C>(f: (a: A) => import("fp-ts/lib/Either").Either<B, C>) => (fa: TaskOption<A>) => import("fp-ts/lib/Compactable").Separated<TaskOption<B>, TaskOption<C>>, filter: { | ||
<A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>): (fa: TaskOption<A>) => TaskOption<B>; | ||
<A>(predicate: import("fp-ts/lib/function").Predicate<A>): (fa: TaskOption<A>) => TaskOption<A>; | ||
}, filterMap: <A, B>(f: (a: A) => Option<B>) => (fa: TaskOption<A>) => TaskOption<B>, compact: <A>(fa: TaskOption<Option<A>>) => TaskOption<A>, separate: <A, B>(fa: TaskOption<import("fp-ts/lib/Either").Either<A, B>>) => import("fp-ts/lib/Compactable").Separated<TaskOption<A>, TaskOption<B>>; | ||
export { | ||
@@ -111,2 +127,26 @@ /** | ||
*/ | ||
map }; | ||
map, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
partition, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
partitionMap, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
filter, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
filterMap, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
compact, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
separate }; |
@@ -1,5 +0,6 @@ | ||
import { task, of } from 'fp-ts/lib/Task'; | ||
import { fromEither as optionFromEither, fromNullable as optionFromNullable, toUndefined as optionToUndefined, toNullable as optionToNullable, chain as optionChain } from 'fp-ts/lib/Option'; | ||
import { task, of, map as taskMap } from 'fp-ts/lib/Task'; | ||
import { fromEither as optionFromEither, fromNullable as optionFromNullable, toUndefined as optionToUndefined, toNullable as optionToNullable, chain as optionChain, mapNullable as optionMapNullable, some as optionSome, none as optionNone, option } from 'fp-ts/lib/Option'; | ||
import { getOptionM } from 'fp-ts/lib/OptionT'; | ||
import { pipeable } from 'fp-ts/lib/pipeable'; | ||
import { getFilterableComposition } from 'fp-ts/lib/Filterable'; | ||
const T = getOptionM(task); | ||
@@ -72,16 +73,21 @@ /** | ||
export function chainOption(f) { | ||
return ma => task.map(ma, optionChain(f)); | ||
return taskMap(optionChain(f)); | ||
} | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
export function mapNullable(f) { | ||
return taskMap(optionMapNullable(f)); | ||
} | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
export function tryCatch(f) { | ||
return () => f().then(a => optionSome(a), () => optionNone); | ||
} | ||
/** | ||
* @since 0.1.0 | ||
*/ | ||
export const taskOption = { | ||
URI, | ||
map: T.map, | ||
of: some, | ||
ap: T.ap, | ||
chain: T.chain, | ||
alt: T.alt | ||
}; | ||
const { alt, ap, apFirst, apSecond, chain, chainFirst, flatten, map } = pipeable(taskOption); | ||
export const taskOption = Object.assign({ URI, map: T.map, of: some, ap: T.ap, chain: T.chain, alt: T.alt }, getFilterableComposition(task, option)); | ||
const { alt, ap, apFirst, apSecond, chain, chainFirst, flatten, map, partition, partitionMap, filter, filterMap, compact, separate } = pipeable(taskOption); | ||
export { | ||
@@ -119,2 +125,26 @@ /** | ||
*/ | ||
map }; | ||
map, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
partition, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
partitionMap, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
filter, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
filterMap, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
compact, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
separate }; |
@@ -6,2 +6,4 @@ import { Alt1 } from 'fp-ts/lib/Alt'; | ||
import { TaskEither } from 'fp-ts/lib/TaskEither'; | ||
import { Lazy } from 'fp-ts/lib/function'; | ||
import { Filterable1 } from 'fp-ts/lib/Filterable'; | ||
declare module 'fp-ts/lib/HKT' { | ||
@@ -74,6 +76,20 @@ interface URItoKind<A> { | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
export declare function mapNullable<A, B>(f: (a: A) => B | null | undefined): (ma: TaskOption<A>) => TaskOption<B>; | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
export declare function tryCatch<A>(f: Lazy<Promise<A>>): TaskOption<A>; | ||
/** | ||
* @since 0.1.0 | ||
*/ | ||
export declare const taskOption: Monad1<URI> & Alt1<URI>; | ||
declare const alt: <A>(that: () => TaskOption<A>) => (fa: TaskOption<A>) => TaskOption<A>, ap: <A>(fa: TaskOption<A>) => <B>(fab: TaskOption<(a: A) => B>) => TaskOption<B>, apFirst: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<A>, apSecond: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<B>, chain: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<B>, chainFirst: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<A>, flatten: <A>(mma: TaskOption<TaskOption<A>>) => TaskOption<A>, map: <A, B>(f: (a: A) => B) => (fa: TaskOption<A>) => TaskOption<B>; | ||
export declare const taskOption: Monad1<URI> & Alt1<URI> & Filterable1<URI>; | ||
declare const alt: <A>(that: () => TaskOption<A>) => (fa: TaskOption<A>) => TaskOption<A>, ap: <A>(fa: TaskOption<A>) => <B>(fab: TaskOption<(a: A) => B>) => TaskOption<B>, apFirst: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<A>, apSecond: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<B>, chain: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<B>, chainFirst: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<A>, flatten: <A>(mma: TaskOption<TaskOption<A>>) => TaskOption<A>, map: <A, B>(f: (a: A) => B) => (fa: TaskOption<A>) => TaskOption<B>, partition: { | ||
<A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>): (fa: TaskOption<A>) => import("fp-ts/lib/Compactable").Separated<TaskOption<A>, TaskOption<B>>; | ||
<A>(predicate: import("fp-ts/lib/function").Predicate<A>): (fa: TaskOption<A>) => import("fp-ts/lib/Compactable").Separated<TaskOption<A>, TaskOption<A>>; | ||
}, partitionMap: <A, B, C>(f: (a: A) => import("fp-ts/lib/Either").Either<B, C>) => (fa: TaskOption<A>) => import("fp-ts/lib/Compactable").Separated<TaskOption<B>, TaskOption<C>>, filter: { | ||
<A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>): (fa: TaskOption<A>) => TaskOption<B>; | ||
<A>(predicate: import("fp-ts/lib/function").Predicate<A>): (fa: TaskOption<A>) => TaskOption<A>; | ||
}, filterMap: <A, B>(f: (a: A) => Option<B>) => (fa: TaskOption<A>) => TaskOption<B>, compact: <A>(fa: TaskOption<Option<A>>) => TaskOption<A>, separate: <A, B>(fa: TaskOption<import("fp-ts/lib/Either").Either<A, B>>) => import("fp-ts/lib/Compactable").Separated<TaskOption<A>, TaskOption<B>>; | ||
export { | ||
@@ -111,2 +127,26 @@ /** | ||
*/ | ||
map }; | ||
map, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
partition, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
partitionMap, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
filter, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
filterMap, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
compact, | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
separate }; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,2 +18,3 @@ var Task_1 = require("fp-ts/lib/Task"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var Filterable_1 = require("fp-ts/lib/Filterable"); | ||
var T = OptionT_1.getOptionM(Task_1.task); | ||
@@ -82,17 +94,24 @@ /** | ||
function chainOption(f) { | ||
return function (ma) { return Task_1.task.map(ma, Option_1.chain(f)); }; | ||
return Task_1.map(Option_1.chain(f)); | ||
} | ||
exports.chainOption = chainOption; | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
function mapNullable(f) { | ||
return Task_1.map(Option_1.mapNullable(f)); | ||
} | ||
exports.mapNullable = mapNullable; | ||
/** | ||
* @since 0.1.5 | ||
*/ | ||
function tryCatch(f) { | ||
return function () { return f().then(function (a) { return Option_1.some(a); }, function () { return Option_1.none; }); }; | ||
} | ||
exports.tryCatch = tryCatch; | ||
/** | ||
* @since 0.1.0 | ||
*/ | ||
exports.taskOption = { | ||
URI: exports.URI, | ||
map: T.map, | ||
of: exports.some, | ||
ap: T.ap, | ||
chain: T.chain, | ||
alt: T.alt | ||
}; | ||
var _a = pipeable_1.pipeable(exports.taskOption), alt = _a.alt, ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map; | ||
exports.taskOption = __assign({ URI: exports.URI, map: T.map, of: exports.some, ap: T.ap, chain: T.chain, alt: T.alt }, Filterable_1.getFilterableComposition(Task_1.task, Option_1.option)); | ||
var _a = pipeable_1.pipeable(exports.taskOption), alt = _a.alt, ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map, partition = _a.partition, partitionMap = _a.partitionMap, filter = _a.filter, filterMap = _a.filterMap, compact = _a.compact, separate = _a.separate; | ||
exports.alt = alt; | ||
@@ -106,1 +125,7 @@ exports.ap = ap; | ||
exports.map = map; | ||
exports.partition = partition; | ||
exports.partitionMap = partitionMap; | ||
exports.filter = filter; | ||
exports.filterMap = filterMap; | ||
exports.compact = compact; | ||
exports.separate = separate; |
{ | ||
"name": "fp-ts-contrib", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "A community driven utility package for fp-ts", | ||
@@ -5,0 +5,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145564
4427