How to use the daggy.tagged function in daggy

To help you get started, we’ve selected a few daggy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fantasyland / fantasy-tuples / test / nested.js View on Github external
const {tagged} = require('daggy');
const {nested, Tuple} = require('../fantasy-tuples');
const {isNumber, isString, isInstanceOf} = require('fantasy-helpers');
const env = require('fantasy-environment')();

const Sum = tagged('x');

Sum.prototype.equals = function(b) {
    return Setoid(λ).equals(this, b);
}

const λ = env
    .method('concat', isString, (a, b) => a + b)
    .method('map', isString, (a, f) => f(a))
    .method('equals', isString, (a, b) => a === b)
    .method('concat', isNumber, (a, b) => a + b)
    .method('map', isNumber, (a, f) => f(a))
    .method('equals', isNumber, (a, b) => a === b);

function Monoid(a) {
    return {
        empty: () => Sum(0),
github fantasyland / fantasy-check / test / instances / product.js View on Github external
'use strict';

const {tagged} = require('daggy');
const Product = tagged('x');

Product.of = Product;
Product.empty = () => Product(1);
Product.prototype.chain = function(f) {
    return f(this.x);
};
Product.prototype.concat = function(x) {
    return this.chain(a => x.map(b => a * b));
};
Product.prototype.map = function(f) {
    return this.chain(x => Product.of(f(x)));
};

module.exports = Product;
github fantasyland / fantasy-frees / examples / interpreter-coproduct.js View on Github external
'use strict';

const daggy = require('daggy');

const {compose, identity} = require('fantasy-combinators');
const {Free} = require('./../fantasy-frees');
const Coproduct = require('fantasy-coproducts');
const IO = require('fantasy-io');


const FPrint = daggy.tagged('s', 'a');
const FRead = daggy.tagged('f');
const unit = daggy.tagged('x');
const Unit = () => unit('');

const Logger = daggy.taggedSum({
    Error: ['x', 'a'],
    Debug: ['x', 'a']
});

FPrint.prototype.map = function(f) {
    return FPrint(this.s, f(this.a));
};

FRead.prototype.map = function(f) {
    return FRead(compose(f)(this.f));
};
github fantasyland / fantasy-monoids / src / unit.js View on Github external
'use strict';

const {tagged} = require('daggy');
const {empty, of, concat} = require('fantasy-land');

const Unit = tagged('x');

Unit[empty] = () => Unit({});
Unit[of] = Unit[empty];

Unit.prototype[concat] = function(y) {
    return Unit({});
};

module.exports = Unit;
github fantasyland / fantasy-identities / src / identity.js View on Github external
Identity.IdentityT = (M) => {
    const IdentityT = daggy.tagged('run');
    IdentityT.lift = IdentityT;
    IdentityT.of = (a) => IdentityT(M.of(a));
    IdentityT.prototype.chain = function(f) {
        return IdentityT(this.run.chain((x) => f(x).run));
    };
    IdentityT.prototype.map = function(f) {
        return this.chain((a) => IdentityT.of(f(a)));
    };
    IdentityT.prototype.ap = function(a) {
        return this.chain((f) => a.map(f));
    };
    return IdentityT;
};
github fantasyland / fantasy-lenses / src / internal / forget.js View on Github external
const Forget = M => {
    const Forget = tagged('runForget');
    const constM = Const(M);

    Forget.prototype.dimap = function(f, g) {
        return Forget(x => this.runForget(f(x)));
    };

    Forget.prototype.first = function() {
        return Forget(x => this.runForget(x._1));
    };

    Forget.prototype.second = function() {
        return Forget(x => this.runForget(x._2));
    };

    Forget.prototype.left = function() {
        return Forget(x => x.fold(this.runForget, M.empty));
github fantasyland / fantasy-maybes / src / option.js View on Github external
Option.OptionT = (M) => {
    const OptionT = tagged('run');
    OptionT.prototype.fold = function(f, g) {
        return this.run[chain]((o) => M[of](o.fold(f, g)));
    };
    OptionT[of] = (x) => OptionT(M[of](Option.Some(x)));
    OptionT.prototype.orElse = function(b) {
        return OptionT(this.run[chain]((a) => {
            return a.fold(
                (x) => M[of](a),
                () => b.run
            );
        }));
    };
    OptionT.prototype.getOrElse = function(x) {
        return this.run[chain]((o) => M[of](o.getOrElse(x)));
    };
    OptionT.prototype[chain] = function(f) {
github fantasyland / fantasy-frees / src / coyoneda.js View on Github external
'use strict';

const {compose, identity} = require('fantasy-combinators');
const {tagged} = require('daggy');
const {map} = require('fantasy-land');

const Coyoneda = tagged('f', 'x');

Coyoneda.lift = function(x) {
    return Coyoneda(identity, x);
};

Coyoneda.prototype[map] = function(f) {
    return Coyoneda(compose(f)(this.f), this.x);
};

Coyoneda.prototype.lower = function() {
    return this.x[map](this.f);
};

module.exports = Coyoneda;
github fantasyland / fantasy-land / internal / sum.js View on Github external
'use strict';

const {tagged} = require('daggy');

const fl = require('..');
const {equality} = require('./func');

const Sum = module.exports = tagged('v');

Sum[fl.of] = Sum;
Sum[fl.empty] = () => Sum(0);
Sum.prototype[fl.map] = function(f) {
  return Sum(f(this.v));
};
Sum.prototype[fl.concat] = function(x) {
  return Sum(this.v + x.v);
};
Sum.prototype[fl.equals] = function(x) {
  return equality(this.v, x.v);
};
Sum.prototype[fl.invert] = function() {
  return Sum(this.v >= 0 ? -Math.abs(this.v) : Math.abs(this.v));
};
github fantasyland / fantasy-frees / src / yoneda.js View on Github external
'use strict';

const {compose, identity} = require('fantasy-combinators');
const {tagged} = require('daggy');
const {map} = require('fantasy-land');

const Yoneda = tagged('f');

Yoneda.lift = (x) => Yoneda((y) => x[map](y));

Yoneda.prototype[map] = function(f) {
    return Yoneda((x) => this.run(compose(x)(f)));
};

Yoneda.prototype.lower = function() {
    return this.f(identity);
};

Yoneda.prototype.run = function(k) {
    return this.f(k);
};

module.exports = Yoneda;

daggy

Library for creating tagged constructors.

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Popular daggy functions