# How to use the sanctuary-def.env function in sanctuary-def

## To help you get started, we’ve selected a few sanctuary-def 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.

pipeos-one / pipeline-meteor / imports / client / templates / main / main.js View on Github
``````})

console.log(SANCT);

//    Integer :: Type
const Integer = SANCT.NullaryType
('my-package/Integer')
('http://example.com/my-package#Integer')
(x =&gt; typeof x === 'number' &amp;&amp;
Math.floor (x) === x &amp;&amp;
x &gt;= Number.MIN_SAFE_INTEGER &amp;&amp;
x &lt;= Number.MAX_SAFE_INTEGER);

window.def = HMD.create({
checkTypes: true,
env: SANCT.env.concat([Integer]),
});

// const sum = def(
//   'sum :: Integer -&gt; Integer -&gt; Integer -&gt; Integer',
//   (a, b, c) =&gt; a + b + c
// );

// eval("const sum = def('sum :: Integer -&gt; Integer -&gt; Integer -&gt; Integer',(a, b, c) =&gt; a + b + c);")

//sum(x, y, z)
console.log('----', sum(5)(8)(14))

});``````
fabioluz / fun-js / src / fun.js View on Github
``````import Sanctuary from 'sanctuary';
import \$ from 'sanctuary-def';
import Z from 'sanctuary-type-classes';
import Future from 'fluture';
import FutureTypes from 'fluture-sanctuary-types';

const S = Sanctuary.create ({
checkTypes: process.env.NODE_ENV !== 'production',
env: Sanctuary.env.concat (FutureTypes.env)
});

const def = \$.create ({
checkTypes: process.env.NODE_ENV !== 'production',
env: \$.env.concat (FutureTypes.env)
});

\$.a = \$.TypeVariable ('a');
\$.b = \$.TypeVariable ('b');
\$.Either = S.EitherType;
\$.Maybe = S.MaybeType;
\$.Future = FutureTypes.FutureType;

// Extensions
S.chainRej = S.curry2 ((fn, future) => future.chainRej (fn));
S.replace = S.curry3((key, replacement, str) => str.replace (key, replacement));
S.lift4 = S.curry4 ((fn, a1, a2, a3, a4) => Z.ap (Z.ap (Z.ap (Z.map (fn, a1), a2), a3), a4));
S.eitherToFuture = S.either (Future.reject) (Future.of);
S.invoke = fnName => arg => obj => obj[fnName] (arg);

export {``````
xodio / hm-def / test / def.spec.js View on Github
``````('Map')
('someurl')
(S.is (\$.Object))
(S.keys)
(S.values);

const \$Wrapper = \$.UnaryType
('Wrapper')
('someurl')
(S.allPass ([S.is (\$.Object), hasProp ('value')]))
(S.pipe ([S.prop ('value'), S.of (Array)]));

const def = create ({
\$,
checkTypes: true,
env: \$.env.concat ([
\$Map (\$.Unknown) (\$.Unknown),
\$Wrapper (\$.Unknown),
]),
typeClasses: [
Z.Functor,
Z.Semigroup,
],
});

describe ('def', () => {
it ('should work with unary functions', () => {
const foo = def
('foo :: Number -> String')
(x => x.toString ());

assert.strictEqual (foo (42), '42');``````
xodio / hm-def / test / signature.spec.js View on Github
``````it ('should be extracted', () => {
const {name} = resolve (\$) ([]) (\$.env) ('foo :: Number -> Number');
assert.strictEqual (name, 'foo');
});
});``````
xodio / hm-def / test / signature.spec.js View on Github
``````it ('should resolve multiple contraints on same variable', () => {
const tcs = [Z.Monoid, Z.Setoid];
const {constraints} = resolve (\$) (tcs) (\$.env) ('foo :: (Monoid a, Setoid a) => a -> b');
assert.deepEqual (constraints, {a: [Z.Monoid, Z.Setoid]});
});
});``````
futurize / future-io / lib / types.js View on Github
``````const \$ = require('sanctuary-def')
const a = \$.TypeVariable('a')
const b = \$.TypeVariable('b')
const \$IO = \$.UnaryType(
'future-io/IO',
(x) => x && x['@@type'] === 'future-io/IO',
() => []
)
(x) => x && typeof x.fork === 'function',
() => []
)
const env = \$.env.concat([
\$IO,
])
const def = \$.create({ checkTypes: true, env })

module.exports = Object.assign({ def, a, b, \$IO, \$Task }, \$)``````

## sanctuary-def

Run-time type system for JavaScript

MIT