Data Types

ImmutableContext

An ImmutableContext() wraps Sweet’s underlying mutable context in an immutable representation. Basically, it calls mark and reset so you don’t have to.

class ImmutableContext(ctx)

With type parameter A, the value returned by the underlying context (currently this is always a Term).

Import the ImmutableContext() class via:

import { ImmutableContext } from '@sweet-js/helpers/parser';
Arguments:
  • ctx – The transformer context provided by a macro.

ImmutableContext() provides a list-like interface; call :meth:`head` to get the next value (wrapped in a Maybe since the context might be empty) and :meth:`rest` to get the rest.

Either

An fantasy-land compatible implementation of the Either data type.

class Either()

With type parameters L and R for Left() and Right(), respectively.

Import the Either() class via:

import { Either } from '@sweet-js/helpers/either';

The static methods of Either() are:

The prototype methods of Either() are:

class Left(value)

A subclass of Either() traditionally used to represent failure.

With type parameter L for the value Left() wraps.

Import the Left() class via:

import { Left } from '@sweet-js/helpers/either';
Arguments:
  • value (A) – The value to wrap

A subclass of Either() traditionally used to represent success.

With type parameter R for the value Right() wraps.

Import the Right() class via:

import { Right } from '@sweet-js/helpers/either';
Arguments:
  • value (A) – The value to wrap

Maybe

An fantasy-land compatible implementation of the Maybe data type.

class Maybe()

With type parameter A.

Import the Maybe() class via:

import { Maybe } from '@sweet-js/helpers/maybe';

The static methods of Maybe() are:

The prototype mehtods of Maybe() are:

class Just(value)

A subtype of Maybe

With type parameter A.

Import the Just() class via:

import { Just } from '@sweet-js/helpers/maybe';
Arguments:
  • value (A) – The value to wrap.
class Nothing()

A subtype of Maybe

Import the Just() class via:

import { Just } from '@sweet-js/helpers/maybe';