Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return S.isJust(result) ? S.Right(result.value) : S.Left(null)
}
}
/**
* Concats two strings
* @return {Future}
*/
export const prepend = (a: string) => (b: string) => {
const argsAreStrings = typeof a === 'string' && typeof b === 'string'
return argsAreStrings ? Future.of(a + b) : Future.reject('Both args should be strings')
}
/* TYPE CHECKING UTILS */
export const isObject = S.is($.Object)
/* LOGGING UTILS */
export const l = x => {
console.log('!!!!!!!', x)
return x
}
// returns a future
export const lf = x => {
console.log('-------', x)
return Future.of(x)
}
import {unchecked as S} from 'sanctuary';
import $ from 'sanctuary-def';
import Z from 'sanctuary-type-classes';
import {assert} from 'chai';
import {create} from '../src/index';
const hasProp = p => x => x[p] !== undefined;
const $Map = $.BinaryType
('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),
]),
import {assert} from 'chai';
import {create} from '../src/index';
const hasProp = p => x => x[p] !== undefined;
const $Map = $.BinaryType
('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', () => {
test ('gets', () => {
eq (S.show (S.gets)) ('gets :: (Any -> Boolean) -> Array String -> a -> Maybe b');
eq (S.gets (S.is ($.Number)) (['x']) ({x: {z: 0}, y: 42})) (S.Nothing);
eq (S.gets (S.is ($.Number)) (['y']) ({x: {z: 0}, y: 42})) (S.Just (42));
eq (S.gets (S.is ($.Number)) (['z']) ({x: {z: 0}, y: 42})) (S.Nothing);
eq (S.gets (S.is ($.Number)) (['x', 'z']) ({x: {z: 0}, y: 42})) (S.Just (0));
eq (S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({x: {z: 0}, y: 42})) (S.Nothing);
eq (S.gets (S.is ($.Number)) ([]) ({x: {z: 0}, y: 42})) (S.Nothing);
eq (S.gets (S.is ($.Object)) ([]) ({x: {z: 0}, y: 42})) (S.Just ({x: {z: 0}, y: 42}));
eq (S.gets (S.is ($.RegExp)) (['x']) ({x: vm.runInNewContext ('/.*/')})) (S.Just (/.*/));
eq (S.gets (S.K (true)) (['valueOf']) (null)) (S.Nothing);
eq (S.gets (S.K (true)) (['valueOf']) (undefined)) (S.Nothing);
eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2]})) (S.Just ([1, 2]));
eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2, null]})) (S.Nothing);
});
import $ from 'sanctuary-def';
export const $Env = $.RecordType ({
repositories: $.Object
});
import $priv from 'sanctuary-def';
import * as Sig from './signature';
const def = $priv.create ({checkTypes: true, env: $priv.env});
const Parameters = $priv.RecordType ({
$: $priv.Object,
checkTypes: $priv.Boolean,
env: $priv.Array ($priv.Type),
typeClasses: $priv.Array ($priv.TypeClass),
});
export const create = def
('create')
({})
([
Parameters,
$priv.String,
$priv.AnyFunction,
$priv.AnyFunction,
])
(({$, checkTypes, env, typeClasses}) => {
const $def = $.create ({checkTypes, env});