toJSON

Converts a Maybe value to a JavaScript object that may be stored as a JSON value.

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

Signature

toJSON()
type JSONSerialisation = {
  "@@type":  String,
  "@@tag":   String,
  "@@value": Object Any
}

Variant . () => JSONSerialisation

Documentation

Converts a Maybe value to a JavaScript object that may be stored as a JSON value.

See the docs for adt/union/derivations/serialization for more details.

Example:

const Maybe = require('folktale/maybe');

Maybe.Just(1).toJSON();
// ==> { '@@type': 'folktale:Maybe', '@@tag': 'Just', '@@value': { value: 1 } }

Maybe.Nothing().toJSON();
// ==> { '@@type': 'folktale:Maybe', '@@tag': 'Nothing', '@@value': {} }

Properties

Source Code

function() {
    return { 
      [typeJsonKey]:  typeName, 
      [tagJsonKey]:   tagName, 
      [valueJsonKey]: mapValues(this, serializeValue) 
    };
  }
Stability
experimental
Licence
MIT
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • @boris-marinov
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)