toJSON

Converts a Result 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 Result 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 Result = require('folktale/result');

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

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

Result.Error(undefined).toJSON();
// ==> { '@@type': 'folktale:Result', '@@tag': 'Error', '@@value': { value: null } }

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/)