Immutable

stdtraits~ Immutable

Source:

This is a flag trait that in­dic­ates whether a type is im­mut­able.

const {Im­mut­able, isIm­mut­able, typeIs­Im­mut­able} = re­quire('fer­rum');

// Mark a cus­tom type as im­mut­able
class Foo {
  [Im­mut­able.sym]() {}
};

// Or al­tern­at­ively
Im­mut­able.impl(Foo, true);

// Mark a cus­tom value as im­mut­able
const bar = {};
Im­mut­able.im­pl­Static(bar, true);

// Test a type for im­mut­ab­il­ity
typeIs­Im­mut­able(Foo); // => true
typeIs­Im­mut­able(Num­ber); // => true
typeIs­Im­mut­able(Ob­ject); // => false

// Test a value for im­mut­ab­il­ity
isIm­mut­able(42); // => true
isIm­mut­able({}); // => false
isIm­mut­able(bar); // => true

// Any other classes will not be con­sidered im­mut­able by de­fault
class Bang {};
typeIs­Im­mut­able(Bang); // => false

Since javas­cript has not real way to en­force ab­so­lute im­mut­ab­il­ity this trait con­siders any­thing im­mut­able that is hard to mutate or really not sup­posed to be mutated. Func­tion is con­sidered im­mut­able des­pite it be­ing pos­sible to as­sign para­met­ers to func­tions...

This is used in a couple paces; spe­cific­ally it is used as a list of types that should be left alone in deep­clone and shal­low­clone.

See: isIm­mut­able See: typeIs­Im­mut­able

By de­fault im­ple­men­ted for: String, Num­ber, Boolean, Reg­Exp, Date, Sym­bol, Func­tion, null, un­defined