New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

functio

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

functio - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

dist/interfaces/either-side.d.ts

6

CHANGELOG.md
# CHANGELOG
## Unreleased - [DIFF](https://github.com/ElateralLtd/ui-components/compare/v0.1.0...HEAD)
## Unreleased - [DIFF](https://github.com/ElateralLtd/ui-components/compare/v0.2.0...HEAD)
## 0.2.0 - 2021-02-25 - [DIFF](https://github.com/ElateralLtd/ui-components/compare/v0.1.0...v0.2.0)
- Added `maybe` util
- Updated `isNothing` property on `Maybe` container to be public
## 0.1.0 - 2021-02-25 - [DIFF](https://github.com/ElateralLtd/ui-components/compare/v0.0.1...v0.1.0)

@@ -6,0 +10,0 @@ - Added `id` util

8

dist/containers/container/container.d.ts
import { Map } from 'types';
import { IContainer } from 'interfaces';
declare class Container<T> implements IContainer<T> {
readonly value: T;
static of<T>(value: T): Container<T>;
declare class Container<A> implements IContainer<A> {
readonly value: A;
static of<C>(value: C): Container<C>;
private constructor();
map<O>(map: Map<T, O>): Container<O>;
map<B>(map: Map<A, B>): Container<B>;
inspect(): string;
}
export default Container;

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

import { IEither } from 'interfaces';
import { IEitherSide } from 'interfaces';
import Left from './left';

@@ -7,4 +7,4 @@ import Right from './right';

static Right: typeof Right;
static of<T>(value: T): IEither<T>;
static of<A>(value: A): IEitherSide<A>;
}
export default Either;
import { Map } from 'types';
import { IEither } from 'interfaces';
declare class Left<T> implements IEither<T> {
readonly value: T;
static of<T>(value: T): Left<T>;
import { IEitherSide } from 'interfaces';
declare class Left<A> implements IEitherSide<A> {
readonly value: A;
static of<C>(value: C): Left<C>;
private constructor();
map<O>(map: Map<T, O>): Left<T>;
map<B>(map: Map<A, B>): Left<A>;
inspect(): string;
}
export default Left;
import { Map } from 'types';
import { IEither } from 'interfaces';
declare class Right<T> implements IEither<T> {
readonly value: T;
static of<T>(value: T): Right<T>;
import { IEitherSide } from 'interfaces';
declare class Right<A> implements IEitherSide<A> {
readonly value: A;
static of<C>(value: C): Right<C>;
private constructor();
map<O>(map: Map<T, O>): Right<O>;
map<B>(map: Map<A, B>): Right<B>;
inspect(): string;
}
export default Right;
import { Map } from 'types';
import { IContainer } from 'interfaces';
declare class Maybe<T> implements IContainer<T> {
readonly value: T;
static of<T>(value: T): Maybe<T>;
declare class Maybe<A> implements IContainer<A> {
readonly value: A;
static of<C>(value: C): Maybe<C>;
private constructor();
map<O>(map: Map<T, O>): Maybe<T | O>;
map<B>(map: Map<A, B>): Maybe<A | B>;
inspect(): string;
private get isNothing();
get isNothing(): boolean;
}
export default Maybe;
import { Map } from 'types';
interface IContainer<T> {
readonly value: T;
map<O>(map: Map<T, O>): IContainer<T | O>;
interface IContainer<A> {
readonly value: A;
map<B>(map: Map<A, B>): IContainer<A | B>;
inspect: () => string;
}
export default IContainer;
import IContainer from './container';
declare type IEither<T> = IContainer<T>;
declare type IEither<L, R> = IContainer<L | R>;
export default IEither;
export { default as IContainer } from './container';
export { default as IEitherSide } from './either-side';
export { default as IEither } from './either';

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

export declare type Map<I, O> = (value: I) => O;
export declare type Map<A, B> = (value: A) => B;
export declare type O = {

@@ -3,0 +3,0 @@ [key: string]: unknown;

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

export declare type Handler<V, R> = (value: V) => R;
export declare type Handler<A, B> = (value: A) => B;

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

declare const id: <T>(value: T) => T;
declare const id: <A>(value: A) => A;
export default id;

@@ -8,2 +8,3 @@ export { default as compose } from './compose';

export { default as left } from './left';
export { default as maybe } from './maybe';
export { default as prop } from './prop';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prop = exports.left = exports.isNil = exports.inspect = exports.id = exports.either = exports.curry = exports.compose = void 0;
exports.prop = exports.maybe = exports.left = exports.isNil = exports.inspect = exports.id = exports.either = exports.curry = exports.compose = void 0;
var compose_1 = require("./compose");

@@ -18,3 +18,5 @@ Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_1.default; } });

Object.defineProperty(exports, "left", { enumerable: true, get: function () { return left_1.default; } });
var maybe_1 = require("./maybe");
Object.defineProperty(exports, "maybe", { enumerable: true, get: function () { return maybe_1.default; } });
var prop_1 = require("./prop");
Object.defineProperty(exports, "prop", { enumerable: true, get: function () { return prop_1.default; } });
import { IEither } from 'interfaces';
declare const left: <T>(value: T) => IEither<T>;
declare const left: <A>(value: A) => IEither<A, unknown>;
export default left;
{
"name": "functio",
"version": "0.1.0",
"version": "0.2.0",
"description": "A set of functional tools.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -5,17 +5,17 @@ import { Map } from 'types';

class Container<T> implements IContainer<T> {
readonly value: T;
class Container<A> implements IContainer<A> {
readonly value: A;
static of<T>(value: T): Container<T> {
return new Container<T>(value);
static of<C>(value: C): Container<C> {
return new Container<C>(value);
}
private constructor(value: T) {
private constructor(value: A) {
this.value = value;
}
map<O>(map: Map<T, O>): Container<O> {
map<B>(map: Map<A, B>): Container<B> {
const mappedValue = map(this.value);
return Container.of<O>(mappedValue);
return Container.of<B>(mappedValue);
}

@@ -22,0 +22,0 @@

@@ -6,3 +6,3 @@ import Either from '.';

it('should create container for a given value', () => {
const either = Either.of('value');
const either = Either.of<string>('value');

@@ -22,3 +22,3 @@ expect(either).toBeInstanceOf(Right);

const value = 'value';
const either = Either.of(value);
const either = Either.of<string>(value);
const inspectedValue = either.inspect();

@@ -25,0 +25,0 @@ const expectedInspectedvalue = `Right('${value}')`;

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

import { IEither } from 'interfaces';
import { IEitherSide } from 'interfaces';

@@ -10,4 +10,4 @@ import Left from './left';

static of<T>(value: T): IEither<T> {
return Right.of<T>(value);
static of<A>(value: A): IEitherSide<A> {
return Right.of<A>(value);
}

@@ -14,0 +14,0 @@ }

import { Map } from 'types';
import { inspect } from 'utils';
import { IEither } from 'interfaces';
import { IEitherSide } from 'interfaces';
class Left<T> implements IEither<T> {
readonly value: T;
class Left<A> implements IEitherSide<A> {
readonly value: A;
static of<T>(value: T): Left<T> {
return new Left<T>(value);
static of<C>(value: C): Left<C> {
return new Left<C>(value);
}
private constructor(value: T) {
private constructor(value: A) {
this.value = value;
}
map<O>(map: Map<T, O>): Left<T> {
map<B>(map: Map<A, B>): Left<A> {
return this;

@@ -18,0 +18,0 @@ }

import { Map } from 'types';
import { inspect } from 'utils';
import { IEither } from 'interfaces';
import { IEitherSide } from 'interfaces';
class Right<T> implements IEither<T> {
readonly value: T;
class Right<A> implements IEitherSide<A> {
readonly value: A;
static of<T>(value: T): Right<T> {
return new Right<T>(value);
static of<C>(value: C): Right<C> {
return new Right<C>(value);
}
private constructor(value: T) {
private constructor(value: A) {
this.value = value;
}
map<O>(map: Map<T, O>): Right<O> {
map<B>(map: Map<A, B>): Right<B> {
const mappedValue = map(this.value);
return Right.of<O>(mappedValue);
return Right.of<B>(mappedValue);
}

@@ -21,0 +21,0 @@

@@ -5,14 +5,14 @@ import { Map } from 'types';

class Maybe<T> implements IContainer<T> {
readonly value: T;
class Maybe<A> implements IContainer<A> {
readonly value: A;
static of<T>(value: T): Maybe<T> {
return new Maybe(value);
static of<C>(value: C): Maybe<C> {
return new Maybe<C>(value);
}
private constructor(value: T) {
private constructor(value: A) {
this.value = value;
}
map<O>(map: Map<T, O>): Maybe<T | O> {
map<B>(map: Map<A, B>): Maybe<A | B> {
if (this.isNothing) {

@@ -23,3 +23,3 @@ return this;

return Maybe.of<O>(mappedValue);
return Maybe.of<B>(mappedValue);
}

@@ -38,3 +38,3 @@ }

private get isNothing(): boolean {
get isNothing(): boolean {
return isNil(this.value);

@@ -41,0 +41,0 @@ }

import { Map } from 'types';
interface IContainer<T> {
readonly value: T;
map<O>(map: Map<T, O>): IContainer<T | O>;
interface IContainer<A> {
readonly value: A;
map<B>(map: Map<A, B>): IContainer<A | B>;
inspect: () => string;

@@ -7,0 +7,0 @@ }

import IContainer from './container';
type IEither<T> = IContainer<T>;
type IEither<L, R> = IContainer<L | R>;
export default IEither;
export { default as IContainer } from './container';
export { default as IEitherSide } from './either-side';
export { default as IEither } from './either';

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

export type Map<I, O> = (value: I) => O;
export type Map<A, B> = (value: A) => B;

@@ -3,0 +3,0 @@ export type O = { [key: string]: unknown };

import { F } from 'types';
// compose :: ((y -> z), (x -> y), ..., (a -> b)) -> a -> z
const compose = (...fns: F[]): F => (

@@ -4,0 +6,0 @@ (...args: unknown[]) => {

import { F } from 'types';
// curry :: ((a, b, ...) -> c) -> a -> b -> ... -> c
const curry = (fn: F): F => (

@@ -4,0 +6,0 @@ function $curry(...args: unknown[]): F | unknown {

@@ -7,8 +7,10 @@ import { curry } from 'utils';

const either = <V, R>(left: Handler<V, R>, right: Handler<V, R>, either: IEither<V>): R | undefined => {
// either :: (a -> c) -> (b -> c) -> Either a b -> c | Undefined
const either = <A, B, C>(left: Handler<A, C>, right: Handler<B, C>, either: IEither<A, B>): C | undefined => {
switch (either.constructor) {
case Either.Left:
return left(either.value);
return left(<A>either.value);
case Either.Right:
return right(either.value);
return right(<B>either.value);
default:

@@ -15,0 +17,0 @@ return undefined;

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

export type Handler<V, R> = (value: V) => R;
export type Handler<A, B> = (value: A) => B;

@@ -1,3 +0,5 @@

const id = <T>(value: T): T => value;
// identity :: a -> a
const id = <A>(value: A): A => value;
export default id;

@@ -8,2 +8,3 @@ export { default as compose } from './compose';

export { default as left } from './left';
export { default as maybe } from './maybe';
export { default as prop } from './prop';

@@ -5,2 +5,4 @@ import { O, F } from 'types';

// inspect :: a -> String
const inspectFunction = (fn: F): string => (

@@ -7,0 +9,0 @@ `function ${fn.name}() { }` || fn.toString()

@@ -0,1 +1,3 @@

// isNil :: a -> Bool
const isNil = (value: unknown): boolean => {

@@ -2,0 +4,0 @@ const isNull = value === null;

import { Either } from 'containers';
import { IEither } from 'interfaces';
const left = <T>(value: T): IEither<T> => (
Either.Left.of<T>(value)
// left :: a -> Either.Left a
const left = <A>(value: A): IEither<A, unknown> => (
Either.Left.of<A>(value)
);
export default left;
import { curry } from 'utils';
import { O } from 'types';
const prop = <T>(key: string, obj: O): T => (
<T>obj[key]
// prop :: { p: a } -> a | Undefined
const prop = <A>(key: string, obj: O): A => (
<A>obj[key]
);
export default curry(prop);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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