Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@sweet-monads/interfaces
Advanced tools
Collection of interfaces which describe functional programming abstractions.
sweet-monads — easy-to-use monads implementation with static types definition and separated packages.
npm install @sweet-monads/interfaces
import { Functor } from "@sweet-monads/interfaces";
class Container<T> implements Functor<T> {
map<A>(fn: (i: T) => A): Container<A> {
return new Container<A>();
}
}
https://wiki.haskell.org/Functor
An abstract datatype Functor<A>
, which has the ability for it's value(s) to be mapped over can become an instance of the Functor interface. That is to say, a new Functor, Functor<B>
can be made from Functor<A>
by transforming all of it's value(s), whilst leaving the structure of f itself unmodified.
Functors are required to obey certain laws in regards to their mapping. Ensuring instances of Functor obey these laws means the behaviour of fmap remains predictable.
Methods:
Functor#map
function map<A, B>(f: (x: A) => B): Functor<B>;
map<A, B>(f: (x: A) => B): Functor<B>;
const f = new SomeFunctorImplementation(); // for all functors
const id = x => x;
expect( f.map(id) ).toEqual( f );
declare function twice(x: number): number; // for all functions
declare function toString(x: number): string; // for all functions
const f = new SomeFunctorImplementation<number>();
expect( f.map(x => toString(twice(x))) ).toEqual( f.map(twice).map(toString) );
https://wiki.haskell.org/Applicative_functor
This module describes a structure intermediate between a functor and a monad (technically, a strong lax monoidal functor). Compared with monads, this interface lacks the full power of the binding operation chain
.
Methods:
Applicative.from
function from<A>(x: A): Applicative<A>;
Applicative#apply
apply<A, B>(this: Applicative<(a: A) => B>, arg: Applicative<A>): Applicative<B>;
apply<A, B>(this: Applicative<A>, fn: Applicative<(a: A) => B>): Applicative<B>;
Functor
implementation.
static from<A>(x: A): Applicative<A>;
apply<A, B>(this: Applicative<(a: A) => B>, arg: Applicative<A>): Applicative<B>;
apply<A, B>(this: Applicative<A>, fn: Applicative<(a: A) => B>): Applicative<B>;
declare var x: Applicative<unknown>;
const id = x => x;
expect( SomeApplicative.from(id).apply(x) ).toEqual( x );
declare var x: unknown;
declare var f: (x: unknown) => unknown;
expect( SomeApplicative.from(f).apply(x) ).toEqual( SomeApplicative.from(f(x)) );
https://wiki.haskell.org/Monad
Monads can be thought of as composable computation descriptions. The essence of monad is thus separation of composition timeline from the composed computation's execution timeline, as well as the ability of computation to implicitly carry extra data, as pertaining to the computation itself, in addition to its one (hence the name) output, that it will produce when run (or queried, or called upon). This lends monads to supplementing pure calculations with features like I/O, common environment, updatable state, etc.
Methods:
Monad#chain
function chain<A, B>(f: (x: A) => Monad<B>): Monad<B>;
Monad#join
function join<T>(this: Monad<Monad<T>>): Monad<T>;
Applicative
implementation.
chain<A, B>(f: (x: A) => Monad<B>): Monad<B>;
join<T>(this: Monad<Monad<T>>): Monad<T>;
declare var x: unknown;
declare function f(x: unknown): Monad<unknown>;
expect( SomeMonad.from(x).chain(f) ).toEqual( f(x) );
declare var mx: Monad<unknown>;
declare function f(x: unknown): Monad<unknown>;
expect( mx.chain(SomeMonad.from) ).toEqual( mx );
declare var mx: Monad<unknown>;
declare function f(x: unknown): Monad<unknown>;
declare function g(x: unknown): Monad<unknown>;
expect( mx.chain(x => f(x).chain(g)) ).toEqual( mx.chain(f).chain(g) );
MIT (c) Artem Kobzar see LICENSE file.
FAQs
Monad interfaces
The npm package @sweet-monads/interfaces receives a total of 7,147 weekly downloads. As such, @sweet-monads/interfaces popularity was classified as popular.
We found that @sweet-monads/interfaces demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.