Ramda Adjunct 2.31.0

Identity

RA. Identity

The simplest fantasy-land compatible monad which attaches no information to values.

The Identity type is a very simple type that has no interesting side effects and is effectively just a container of some value. So why does it exist ? The Identity type is often used as the base monad of a monad transformer when no other behaviour is required.

Constructor

new Identity(value) → {RA.Identity}

Source:
Since:
Implements:

Private constructor. Use Identity.of instead.

Parameters:
Name Type Description
value *
Returns:
Type
RA.Identity

Members

(static) @@type

Source:

Methods

(static) of(value) → {RA.Identity}

Source:
Signature:
  • of :: Applicative f => a -> f a

Fantasy land Applicative specification.

Example
const a = Identity.of(1); //=> Identity(1)
Parameters:
Name Type Description
value *
Returns:
Type
RA.Identity

ap(applyWithFn) → {RA.Identity}

Source:
Signature:
  • ap :: Apply f => f a ~> f (a -> b) -> f b

Fantasy land Apply specification.

Example
const a = Identity.of(1);
const b = Identity.of(1).map(a => b => a + b);

a.ap(b); //=> Identity(2)
Parameters:
Name Type Description
applyWithFn RA.Identity
Returns:
Type
RA.Identity

chain(fn) → {RA.Identity}

Source:
Signature:
  • chain :: Chain m => m a ~> (a -> m b) -> m b

Fantasy land Chain specification.

Example
const a = Identity.of(1);
const fn = val => Identity.of(val + 1);

a.chain(fn).chain(fn); //=> Identity(3)
Parameters:
Name Type Description
fn function

Function returning the value of the same Chain

Returns:
Type
RA.Identity

concat(semigroup) → {RA.Identity}

Source:
Signature:
  • concat :: Semigroup a => a ~> a -> a

Fantasy land Semigroup specification.

Example
const a = Identity.of(1);
const b = Identity.of(1);
a.concat(b); //=> 2

const c = Identity.of('c');
const d = Identity.of('d');
c.concat(d); //=> 'cd'

const e = Identity.of(['e']);
const f = Identity.of(['f']);
e.concat(f); //=> ['e', 'f']
Parameters:
Name Type Description
semigroup RA.Identity
Returns:
Type
RA.Identity

contramap(fn) → {RA.Identity}

Source:
Signature:
  • contramap :: Contravariant f => f a ~> (b -> a) -> f b

Fantasy land Contravariant specification.

Example
const identity = a => a;
const add1 = a => a + 1;
const divide2 = a => a / 2;

Identity.of(divide2).contramap(add1).get()(3); //=> 2
Identity.of(identity).contramap(divide2).contramap(add1).get()(3); //=> 2
Identity.of(identity).contramap(a => divide2(add1(a))).get()(3); //=> 2
Parameters:
Name Type Description
fn function
Returns:
Type
RA.Identity

empty() → {RA.Identity}

Source:
Signature:
  • empty :: Monoid m => () -> m

Fantasy land Monoid* specification. Partial implementation of Monoid specification. empty method on instance only, returning identity value of the wrapped type. Using R.empty under the hood.

Example
const a = Identity.of('test');
const i = a.empty();

a.concat(i); //=> Identity('string');
i.concat(a); //=> Identity('string');
Returns:
Type
RA.Identity

equals(setoid) → {boolean}

Source:
Signature:
  • equals :: Setoid a => a ~> a -> Boolean

Fantasy land Setoid specification.

Example
const a = Identity.of(1);
const b = Identity.of(1);
const c = Identity.of(2);

a.equals(b); //=> true
a.equals(c); //=> false
Parameters:
Name Type Description
setoid RA.Identity
Returns:
Type
boolean

get() → {*}

Source:

Catamorphism for a value.

Example
const a = Identity.of(1);
a.get(); //=> 1
Returns:
Type
*

lte(ord) → {boolean}

Source:
Signature:
  • lte :: Ord a => a ~> a -> Boolean

Fantasy land Ord specification.

Example
const a = Identity.of(1);
const b = Identity.of(1);
const c = Identity.of(2);

a.lte(b); //=> true
a.lte(c); //=> true
c.lte(a); //=> false
Parameters:
Name Type Description
ord RA.Identity
Returns:
Type
boolean

map(fn) → {RA.Identity}

Source:
Signature:
  • map :: Functor f => f a ~> (a -> b) -> f b

Fantasy land Functor specification.

Example
const a = Identity.of(1);
a.map(a => a + 1); //=> Identity(2)
Parameters:
Name Type Description
fn function
Returns:
Type
RA.Identity