Socket
Socket
Sign inDemoInstall

monocle-ts

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monocle-ts - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

6

CHANGELOG.md

@@ -15,2 +15,8 @@ # Changelog

# 0.4.0
- **Breaking Change**
- upgrade to fp-ts 0.5 (@gcanti)
- currying of all APIs (@gcanti)
# 0.3.2

@@ -17,0 +23,0 @@

77

lib/index.d.ts

@@ -1,2 +0,2 @@

import { HKT } from 'fp-ts/lib/HKT';
import { HKT, HKTS, HKTAs, HKT2S, HKT2As } from 'fp-ts/lib/HKT';
import { Monoid } from 'fp-ts/lib/Monoid';

@@ -7,9 +7,9 @@ import { Applicative } from 'fp-ts/lib/Applicative';

import { Option } from 'fp-ts/lib/Option';
import { Predicate } from 'fp-ts/lib/function';
import { Predicate, Endomorphism } from 'fp-ts/lib/function';
export declare class Iso<S, A> {
get: (s: S) => A;
reverseGet: (a: A) => S;
readonly get: (s: S) => A;
readonly reverseGet: (a: A) => S;
readonly _tag: 'Iso';
constructor(get: (s: S) => A, reverseGet: (a: A) => S);
modify(f: (a: A) => A, s: S): S;
modify(f: Endomorphism<A>): Endomorphism<S>;
/** view an Iso as a Lens */

@@ -57,10 +57,10 @@ asLens(): Lens<S, A>;

export declare class Lens<S, A> {
get: (s: S) => A;
set: (a: A, s: S) => S;
readonly get: (s: S) => A;
readonly set: (a: A) => Endomorphism<S>;
static fromPath: typeof lensFromPath;
readonly _tag: 'Lens';
constructor(get: (s: S) => A, set: (a: A, s: S) => S);
constructor(get: (s: S) => A, set: (a: A) => Endomorphism<S>);
/** generate a lens from a type and a prop */
static fromProp<T, P extends keyof T>(prop: P): Lens<T, T[P]>;
modify(f: (a: A) => A, s: S): S;
modify(f: Endomorphism<A>): Endomorphism<S>;
/** view a Lens as a Optional */

@@ -94,4 +94,4 @@ asOptional(): Optional<S, A>;

export declare class Prism<S, A> {
getOption: (s: S) => Option<A>;
reverseGet: (a: A) => S;
readonly getOption: (s: S) => Option<A>;
readonly reverseGet: (a: A) => S;
readonly _tag: 'Prism';

@@ -101,4 +101,4 @@ constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S);

static some<A>(): Prism<Option<A>, A>;
modify(f: (a: A) => A, s: S): S;
modifyOption(f: (a: A) => A, s: S): Option<S>;
modify(f: Endomorphism<A>): Endomorphism<S>;
modifyOption(f: Endomorphism<A>): (s: S) => Option<S>;
/** view a Prism as a Optional */

@@ -130,8 +130,8 @@ asOptional(): Optional<S, A>;

export declare class Optional<S, A> {
getOption: (s: S) => Option<A>;
set: (a: A, s: S) => S;
readonly getOption: (s: S) => Option<A>;
readonly set: (a: A) => Endomorphism<S>;
readonly _tag: 'Optional';
constructor(getOption: (s: S) => Option<A>, set: (a: A, s: S) => S);
modify(f: (a: A) => A, s: S): S;
modifyOption(f: (a: A) => A, s: S): Option<S>;
constructor(getOption: (s: S) => Option<A>, set: (a: A) => Endomorphism<S>);
modify(f: Endomorphism<A>): Endomorphism<S>;
modifyOption(f: Endomorphism<A>): (s: S) => Option<S>;
/** view a Optional as a Traversal */

@@ -161,7 +161,7 @@ asTraversal(): Traversal<S, A>;

export declare class Traversal<S, A> {
modifyF: <F>(F: Applicative<F>, f: (a: A) => HKT<F, A>, s: S) => HKT<F, S>;
readonly modifyF: <F>(F: Applicative<F>) => (f: (a: A) => HKT<F, A>) => (s: S) => HKT<F, S>;
readonly _tag: 'Traversal';
constructor(modifyF: <F>(F: Applicative<F>, f: (a: A) => HKT<F, A>, s: S) => HKT<F, S>);
modify(f: (a: A) => A, s: S): S;
set(a: A, s: S): S;
constructor(modifyF: <F>(F: Applicative<F>) => (f: (a: A) => HKT<F, A>) => (s: S) => HKT<F, S>);
modify(f: Endomorphism<A>): Endomorphism<S>;
set(a: A): Endomorphism<S>;
/** view a Traversal as a Fold */

@@ -189,3 +189,3 @@ asFold(): Fold<S, A>;

export declare class Getter<S, A> {
get: (s: S) => A;
readonly get: (s: S) => A;
readonly _tag: 'Getter';

@@ -211,5 +211,6 @@ constructor(get: (s: S) => A);

export declare class Fold<S, A> {
foldMap: <M>(M: Monoid<M>, f: (a: A) => M, s: S) => M;
readonly foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M;
readonly _tag: 'Fold';
constructor(foldMap: <M>(M: Monoid<M>, f: (a: A) => M, s: S) => M);
private foldMapFirst;
constructor(foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M);
/** compose a Fold with a Fold */

@@ -229,18 +230,20 @@ compose<B>(ab: Fold<A, B>): Fold<S, B>;

composeIso<B>(ab: Iso<A, B>): Fold<S, B>;
/** get all the targets of a Fold */
getAll(s: S): Array<A>;
/** find the first target of a Fold matching the predicate */
find(p: Predicate<A>, s: S): Option<A>;
find(p: Predicate<A>): (s: S) => Option<A>;
/** get the first target of a Fold */
headOption(s: S): Option<A>;
}
export interface Fold<S, A> {
/** get all the targets of a Fold */
getAll(s: S): Array<A>;
/** check if at least one target satisfies the predicate */
exist(p: Predicate<A>, s: S): boolean;
exist(p: Predicate<A>): Predicate<S>;
/** check if all targets satisfy the predicate */
all(p: Predicate<A>, s: S): boolean;
all(p: Predicate<A>): Predicate<S>;
}
export declare class Setter<S, A> {
modify: (f: (a: A) => A, s: S) => S;
readonly modify: (f: Endomorphism<A>) => Endomorphism<S>;
readonly _tag: 'Setter';
constructor(modify: (f: (a: A) => A, s: S) => S);
set(a: A, s: S): S;
constructor(modify: (f: Endomorphism<A>) => Endomorphism<S>);
set(a: A): Endomorphism<S>;
/** compose a Setter with a Setter */

@@ -261,7 +264,11 @@ compose<B>(ab: Setter<A, B>): Setter<S, B>;

/** create a Traversal from a Traversable */
fromTraversable<T, A>(T: Traversable<T>): Traversal<HKT<T, A>, A>;
fromTraversable<T extends HKT2S>(T: Traversable<T>): <L, A>() => Traversal<HKT2As<T, L, A>, A>;
fromTraversable<T extends HKTS>(T: Traversable<T>): <A>() => Traversal<HKTAs<T, A>, A>;
fromTraversable<T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A>;
/** create a Fold from a Foldable */
fromFoldable<F, A>(F: Foldable<F>): Fold<HKT<F, A>, A>;
fromFoldable<F extends HKT2S>(F: Foldable<F>): <L, A>() => Fold<HKT2As<F, L, A>, A>;
fromFoldable<F extends HKTS>(F: Foldable<F>): <A>() => Fold<HKTAs<F, A>, A>;
fromFoldable<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A>;
}
export declare const fromTraversable: Ops['fromTraversable'];
export declare const fromFoldable: Ops['fromFoldable'];

@@ -9,3 +9,3 @@ "use strict";

var id = require("fp-ts/lib/Identity");
var con = require("fp-ts/lib/Const");
var const_ = require("fp-ts/lib/Const");
/*

@@ -22,8 +22,10 @@ Laws:

}
Iso.prototype.modify = function (f, s) {
return this.reverseGet(f(this.get(s)));
Iso.prototype.modify = function (f) {
var _this = this;
return function (s) { return _this.reverseGet(f(_this.get(s))); };
};
/** view an Iso as a Lens */
Iso.prototype.asLens = function () {
return new Lens(this.get, this.reverseGet);
var _this = this;
return new Lens(this.get, function (a) { return function (s) { return _this.reverseGet(a); }; });
};

@@ -38,3 +40,3 @@ /** view an Iso as a Prism */

var _this = this;
return new Optional(function (s) { return Option_1.some(_this.get(s)); }, function (a, s) { return _this.reverseGet(a); });
return new Optional(function (s) { return Option_1.some(_this.get(s)); }, function (a) { return function (s) { return _this.reverseGet(a); }; });
};

@@ -44,5 +46,5 @@ /** view an Iso as a Traversal */

var _this = this;
return new Traversal(function (F, f, s) {
return new Traversal(function (F) { return function (f) { return function (s) {
return F.map(function (a) { return _this.reverseGet(a); }, f(_this.get(s)));
});
}; }; });
};

@@ -52,3 +54,3 @@ /** view an Iso as a Fold */

var _this = this;
return new Fold(function (M, f, s) { return f(_this.get(s)); });
return new Fold(function (M) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -63,3 +65,3 @@ /** view an Iso as a Getter */

var _this = this;
return new Setter(function (f, s) { return _this.modify(f, s); });
return new Setter(function (f) { return function (s) { return _this.modify(f)(s); }; });
};

@@ -121,9 +123,10 @@ /** compose an Iso with an Iso */

Lens.fromProp = function (prop) {
return new Lens(function (s) { return s[prop]; }, function (a, s) {
return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) {
return Object.assign({}, s, (_a = {}, _a[prop] = a, _a));
var _a;
});
}; });
};
Lens.prototype.modify = function (f, s) {
return this.set(f(this.get(s)), s);
Lens.prototype.modify = function (f) {
var _this = this;
return function (s) { return _this.set(f(_this.get(s)))(s); };
};

@@ -138,5 +141,5 @@ /** view a Lens as a Optional */

var _this = this;
return new Traversal(function (F, f, s) {
return F.map(function (a) { return _this.set(a, s); }, f(_this.get(s)));
});
return new Traversal(function (F) { return function (f) { return function (s) {
return F.map(function (a) { return _this.set(a)(s); }, f(_this.get(s)));
}; }; });
};

@@ -146,3 +149,3 @@ /** view a Lens as a Setter */

var _this = this;
return new Setter(function (f, s) { return _this.modify(f, s); });
return new Setter(function (f) { return function (s) { return _this.modify(f)(s); }; });
};

@@ -157,3 +160,3 @@ /** view a Lens as a Getter */

var _this = this;
return new Fold(function (M, f, s) { return f(_this.get(s)); });
return new Fold(function (M) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -163,3 +166,3 @@ /** compose a Lens with a Lens */

var _this = this;
return new Lens(function (s) { return ab.get(_this.get(s)); }, function (b, s) { return _this.set(ab.set(b, _this.get(s)), s); });
return new Lens(function (s) { return ab.get(_this.get(s)); }, function (b) { return function (s) { return _this.set(ab.set(b)(_this.get(s)))(s); }; });
};

@@ -215,12 +218,14 @@ /** compose a Lens with a Getter */

};
Prism.prototype.modify = function (f, s) {
return this.modifyOption(f, s).fold(function_1.constant(s), function_1.identity);
Prism.prototype.modify = function (f) {
var _this = this;
return function (s) { return _this.modifyOption(f)(s).fold(function_1.constant(s), function_1.identity); };
};
Prism.prototype.modifyOption = function (f, s) {
Prism.prototype.modifyOption = function (f) {
var _this = this;
return this.getOption(s).map(function (a) { return _this.reverseGet(f(a)); });
return function (s) { return _this.getOption(s).map(function (a) { return _this.reverseGet(f(a)); }); };
};
/** view a Prism as a Optional */
Prism.prototype.asOptional = function () {
return new Optional(this.getOption, this.reverseGet);
var _this = this;
return new Optional(this.getOption, function (a) { return function (s) { return _this.reverseGet(a); }; });
};

@@ -230,5 +235,5 @@ /** view a Prism as a Traversal */

var _this = this;
return new Traversal(function (F, f, s) {
return new Traversal(function (F) { return function (f) { return function (s) {
return _this.getOption(s).fold(function () { return F.of(s); }, function (a) { return F.map(function (fa) { return _this.reverseGet(a); }, f(a)); });
});
}; }; });
};

@@ -238,3 +243,3 @@ /** view a Prism as a Setter */

var _this = this;
return new Setter(function (f, s) { return _this.modify(f, s); });
return new Setter(function (f) { return function (s) { return _this.modify(f)(s); }; });
};

@@ -244,3 +249,3 @@ /** view a Prism as a Fold */

var _this = this;
return new Fold(function (M, f, s) { return _this.getOption(s).fold(function () { return M.empty(); }, f); });
return new Fold(function (M) { return function (f) { return function (s) { return _this.getOption(s).fold(function () { return M.empty(); }, f); }; }; });
};

@@ -296,8 +301,9 @@ /** compose a Prism with a Prism */

}
Optional.prototype.modify = function (f, s) {
return this.modifyOption(f, s).fold(function_1.constant(s), function_1.identity);
Optional.prototype.modify = function (f) {
var _this = this;
return function (s) { return _this.modifyOption(f)(s).fold(function_1.constant(s), function_1.identity); };
};
Optional.prototype.modifyOption = function (f, s) {
Optional.prototype.modifyOption = function (f) {
var _this = this;
return this.getOption(s).map(function (a) { return _this.set(f(a), s); });
return function (s) { return _this.getOption(s).map(function (a) { return _this.set(f(a))(s); }); };
};

@@ -307,5 +313,5 @@ /** view a Optional as a Traversal */

var _this = this;
return new Traversal(function (F, f, s) {
return _this.getOption(s).fold(function () { return F.of(s); }, function (a) { return F.map(function (a) { return _this.set(a, s); }, f(a)); });
});
return new Traversal(function (F) { return function (f) { return function (s) {
return _this.getOption(s).fold(function () { return F.of(s); }, function (a) { return F.map(function (a) { return _this.set(a)(s); }, f(a)); });
}; }; });
};

@@ -315,3 +321,3 @@ /** view an Optional as a Fold */

var _this = this;
return new Fold(function (M, f, s) { return _this.getOption(s).fold(function () { return M.empty(); }, f); });
return new Fold(function (M) { return function (f) { return function (s) { return _this.getOption(s).fold(function () { return M.empty(); }, f); }; }; });
};

@@ -321,3 +327,3 @@ /** view an Optional as a Setter */

var _this = this;
return new Setter(function (f, s) { return _this.modify(f, s); });
return new Setter(function (f) { return function (s) { return _this.modify(f)(s); }; });
};

@@ -327,3 +333,3 @@ /** compose a Optional with a Optional */

var _this = this;
return new Optional(function (s) { return _this.getOption(s).chain(function (a) { return ab.getOption(a); }); }, function (b, s) { return _this.modify(function (a) { return ab.set(b, a); }, s); });
return new Optional(function (s) { return _this.getOption(s).chain(function (a) { return ab.getOption(a); }); }, function (b) { return function (s) { return _this.modify(function (a) { return ab.set(b)(a); })(s); }; });
};

@@ -368,7 +374,9 @@ /** compose an Optional with a Traversal */

}
Traversal.prototype.modify = function (f, s) {
return this.modifyF(id, function (a) { return id.of(f(a)); }, s).extract();
Traversal.prototype.modify = function (f) {
var _this = this;
return function (s) { return _this.modifyF(id)(function (a) { return id.of(f(a)); })(s).extract(); };
};
Traversal.prototype.set = function (a, s) {
return this.modify(function_1.constant(a), s);
Traversal.prototype.set = function (a) {
var _this = this;
return function (s) { return _this.modify(function_1.constant(a))(s); };
};

@@ -378,5 +386,5 @@ /** view a Traversal as a Fold */

var _this = this;
return new Fold(function (M, f, s) {
return _this.modifyF(con.getApplicative(M), function (a) { return new con.Const(f(a)); }, s).fold(function_1.identity);
});
return new Fold(function (M) { return function (f) { return function (s) {
return _this.modifyF(const_.getApplicative(M))(function (a) { return new const_.Const(f(a)); })(s).fold(function_1.identity);
}; }; });
};

@@ -386,3 +394,3 @@ /** view a Traversal as a Setter */

var _this = this;
return new Setter(function (f, s) { return _this.modify(f, s); });
return new Setter(function (f) { return function (s) { return _this.modify(f)(s); }; });
};

@@ -392,5 +400,5 @@ /** compose a Traversal with a Traversal */

var _this = this;
return new Traversal(function (F, f, s) {
return _this.modifyF(F, function (a) { return ab.modifyF(F, f, a); }, s);
});
return new Traversal(function (F) { return function (f) { return function (s) {
return _this.modifyF(F)(function (a) { return ab.modifyF(F)(f)(a); })(s);
}; }; });
};

@@ -436,3 +444,3 @@ /** compose a Traversal with a Fold */

var _this = this;
return new Fold(function (M, f, s) { return f(_this.get(s)); });
return new Fold(function (M) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -475,2 +483,6 @@ /** compose a Getter with a Getter */

this._tag = 'Fold';
this.getAll = foldMap(Monoid_1.monoidArray)(function (a) { return [a]; });
this.exist = foldMap(Monoid_1.monoidAny);
this.all = foldMap(Monoid_1.monoidAll);
this.foldMapFirst = foldMap(option.getFirstMonoid());
}

@@ -480,3 +492,3 @@ /** compose a Fold with a Fold */

var _this = this;
return new Fold(function (M, f, s) { return _this.foldMap(M, function (a) { return ab.foldMap(M, f, a); }, s); });
return new Fold(function (M) { return function (f) { return function (s) { return _this.foldMap(M)(function (a) { return ab.foldMap(M)(f)(a); })(s); }; }; });
};

@@ -507,22 +519,10 @@ /** compose a Fold with a Getter */

};
/** get all the targets of a Fold */
Fold.prototype.getAll = function (s) {
return this.foldMap(Monoid_1.monoidArray, function (a) { return [a]; }, s);
};
/** find the first target of a Fold matching the predicate */
Fold.prototype.find = function (p, s) {
return this.foldMap(option.getFirstMonoid(), function (a) { return (p(a) ? option.of(a) : option.none); }, s);
Fold.prototype.find = function (p) {
return this.foldMapFirst(function (a) { return (p(a) ? option.of(a) : option.none); });
};
/** get the first target of a Fold */
Fold.prototype.headOption = function (s) {
return this.find(function () { return true; }, s);
return this.find(function () { return true; })(s);
};
/** check if at least one target satisfies the predicate */
Fold.prototype.exist = function (p, s) {
return this.foldMap(Monoid_1.monoidAny, p, s);
};
/** check if all targets satisfy the predicate */
Fold.prototype.all = function (p, s) {
return this.foldMap(Monoid_1.monoidAll, p, s);
};
return Fold;

@@ -536,4 +536,5 @@ }());

}
Setter.prototype.set = function (a, s) {
return this.modify(function_1.constant(a), s);
Setter.prototype.set = function (a) {
var _this = this;
return function (s) { return _this.modify(function_1.constant(a))(s); };
};

@@ -543,3 +544,3 @@ /** compose a Setter with a Setter */

var _this = this;
return new Setter(function (f, s) { return _this.modify(function (a) { return ab.modify(f, a); }, s); });
return new Setter(function (f) { return function (s) { return _this.modify(function (a) { return ab.modify(f)(a); })(s); }; });
};

@@ -573,8 +574,8 @@ /** compose a Setter with a Traversal */

Ops.prototype.fromTraversable = function (T) {
return new Traversal(function (F, f, s) {
return T.traverse(F)(f, s);
});
return function () {
return new Traversal(function (F) { return function (f) { return function (s) { return T.traverse(F)(f, s); }; }; });
};
};
Ops.prototype.fromFoldable = function (F) {
return new Fold(function (M, f, s) { return Foldable_1.foldMap(F, M)(f, s); });
return function () { return new Fold(function (M) { return function (f) { return function (s) { return Foldable_1.foldMap(F, M)(f)(s); }; }; }); };
};

@@ -581,0 +582,0 @@ return Ops;

{
"name": "monocle-ts",
"version": "0.3.2",
"version": "0.4.0",
"description": "A porting of scala monocle library to TypeScript",

@@ -29,3 +29,3 @@ "files": ["lib"],

"dependencies": {
"fp-ts": "^0.4.3"
"fp-ts": "^0.5.0"
},

@@ -32,0 +32,0 @@ "devDependencies": {

@@ -35,5 +35,3 @@ A (partial) porting of scala [monocle](https://github.com/julien-truffaut/Monocle) library to TypeScript

function capitalize(s: string): string {
return s.substring(0, 1).toUpperCase() + s.substring(1)
}
const capitalize = (s: string): string => s.substring(0, 1).toUpperCase() + s.substring(1)

@@ -77,3 +75,3 @@ const employee2 = {

.compose(name)
.modify(capitalize, employee)
.modify(capitalize)(employee)
```

@@ -91,3 +89,3 @@

s => s.length > 0 ? some(s[0]) : none,
(a, s) => a + s.substring(1)
a => s => a + s.substring(1)
)

@@ -101,3 +99,3 @@

.compose(firstLetter)
.modify(s => s.toUpperCase(), employee)
.modify(s => s.toUpperCase())(employee)
```

@@ -104,0 +102,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc