|
14 | 14 | if (typeof define === 'function' && define.amd) { |
15 | 15 | define(factory) |
16 | 16 | } else if (typeof module === 'object' && module.exports) { |
17 | | - module.exports = factory(typeof global === 'object' ? global : root) |
| 17 | + module.exports = factory(root) |
18 | 18 | } else { |
19 | | - root.useMonetGlobalObject = |
20 | | - typeof root.useMonetGlobalObject === 'boolean' ? |
21 | | - root.useMonetGlobalObject : |
22 | | - true |
23 | 19 | root.Monet = factory(root) |
24 | 20 | } |
25 | | -}(typeof self !== 'undefined' ? self : this, function (rootGlobalObject) { |
| 21 | +}(typeof self !== 'undefined' ? self : this, function () { |
26 | 22 | 'use strict' |
27 | 23 |
|
28 | | - var root = {} |
29 | | - |
30 | 24 | function assignImp(target, source) { |
31 | 25 | for (var key in source) { // we need only one level of composition |
32 | 26 | // eslint-disable-next-line no-undefined |
|
242 | 236 | } |
243 | 237 | } |
244 | 238 |
|
245 | | - root.List = List |
| 239 | + Monet.List = List |
246 | 240 |
|
247 | 241 | var listForEach = function (effectFn, l) { |
248 | 242 | if (!l.isNil) { |
|
362 | 356 | }, [], this) |
363 | 357 | }, |
364 | 358 | toSet: function () { |
365 | | - if (!rootGlobalObject.Set) { |
366 | | - throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.') |
367 | | - } |
368 | 359 | return new Set(this) |
369 | 360 | }, |
370 | 361 | foldLeft: function (initialValue) { |
|
479 | 470 | // backwards compatibility, deprecated |
480 | 471 | List.prototype.each = List.prototype.forEach |
481 | 472 |
|
482 | | - Nil = root.Nil = new List.fn.init() |
| 473 | + Nil = Monet.Nil = new List.fn.init() |
483 | 474 |
|
484 | 475 | /* |
485 | 476 | * Non-Empty List monad |
|
499 | 490 | return new NEL.fn.init(head, tail) |
500 | 491 | } |
501 | 492 |
|
502 | | - root.NEL = root.NonEmptyList = NEL |
| 493 | + Monet.NEL = Monet.NonEmptyList = NEL |
503 | 494 |
|
504 | 495 | NEL.of = function (a) { |
505 | 496 | return NEL(a, Nil) |
|
637 | 628 |
|
638 | 629 | /* Maybe Monad */ |
639 | 630 |
|
640 | | - var Maybe = root.Maybe = {} |
| 631 | + var Maybe = Monet.Maybe = {} |
641 | 632 |
|
642 | 633 | Maybe.fromFalsy = function (val) { |
643 | 634 | return !val ? Maybe.None() : Maybe.Some(val) |
|
656 | 647 | return Some(a) |
657 | 648 | } |
658 | 649 |
|
659 | | - var Some = Maybe.Just = Maybe.Some = Maybe.some = root.Some = root.Just = function (val) { |
| 650 | + var Some = Maybe.Just = Maybe.Some = Maybe.some = Monet.Some = Monet.Just = function (val) { |
660 | 651 | return new Maybe.fn.init(true, val) |
661 | 652 | } |
662 | 653 |
|
663 | | - var None = Maybe.Nothing = Maybe.None = Maybe.none = root.None = root.Nothing = function () { |
| 654 | + var None = Maybe.Nothing = Maybe.None = Maybe.none = Monet.None = Monet.Nothing = function () { |
664 | 655 | return new Maybe.fn.init(false, null) |
665 | 656 | } |
666 | 657 |
|
|
730 | 721 | }) |
731 | 722 | }, |
732 | 723 | toSet: function () { |
733 | | - if (!rootGlobalObject.Set) { |
734 | | - throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.') |
735 | | - } |
736 | 724 | return new Set(this) |
737 | 725 | }, |
738 | 726 | toList: function () { |
|
803 | 791 | Maybe.isInstance = isInstance(TYPES_NAMES.Maybe) |
804 | 792 | Maybe.isOfType = isOfType(TYPES_NAMES.Maybe) |
805 | 793 |
|
806 | | - var Validation = root.Validation = {} |
| 794 | + var Validation = Monet.Validation = {} |
807 | 795 |
|
808 | | - var Success = Validation.Success = Validation.success = root.Success = function (val) { |
| 796 | + var Success = Validation.Success = Validation.success = Monet.Success = function (val) { |
809 | 797 | return new Validation.fn.init(val, true) |
810 | 798 | } |
811 | 799 |
|
812 | | - var Fail = Validation.Fail = Validation.fail = root.Fail = function (error) { |
| 800 | + var Fail = Validation.Fail = Validation.fail = Monet.Fail = function (error) { |
813 | 801 | return new Validation.fn.init(error, false) |
814 | 802 | } |
815 | 803 |
|
|
923 | 911 | Validation.isInstance = isInstance(TYPES_NAMES.Validation) |
924 | 912 | Validation.isOfType = isOfType(TYPES_NAMES.Validation) |
925 | 913 |
|
926 | | - var Semigroup = root.Semigroup = { |
| 914 | + var Semigroup = Monet.Semigroup = { |
927 | 915 | append: function (a, b) { |
928 | 916 | if (isFunction(a.concat)) { |
929 | 917 | return a.concat(b) |
|
934 | 922 | } |
935 | 923 | } |
936 | 924 |
|
937 | | - var MonadT = root.monadTransformer = root.MonadT = root.monadT = function (monad) { |
| 925 | + var MonadT = Monet.monadTransformer = Monet.MonadT = Monet.monadT = function (monad) { |
938 | 926 | return new MonadT.fn.init(monad) |
939 | 927 | } |
940 | 928 |
|
|
971 | 959 |
|
972 | 960 | MonadT.fn.init.prototype = MonadT.fn |
973 | 961 |
|
974 | | - var IO = root.IO = root.io = function (effectFn) { |
| 962 | + var IO = Monet.IO = Monet.io = function (effectFn) { |
975 | 963 | return new IO.fn.init(effectFn) |
976 | 964 | } |
977 | 965 |
|
|
1023 | 1011 |
|
1024 | 1012 | /* Either Monad */ |
1025 | 1013 |
|
1026 | | - var Either = root.Either = {} |
| 1014 | + var Either = Monet.Either = {} |
1027 | 1015 |
|
1028 | 1016 | Either.of = function (a) { |
1029 | 1017 | return Right(a) |
1030 | 1018 | } |
1031 | 1019 |
|
1032 | | - var Right = Either.Right = Either.right = root.Right = function (val) { |
| 1020 | + var Right = Either.Right = Either.right = Monet.Right = function (val) { |
1033 | 1021 | return new Either.fn.init(val, true) |
1034 | 1022 | } |
1035 | | - var Left = Either.Left = Either.left = root.Left = function (val) { |
| 1023 | + var Left = Either.Left = Either.left = Monet.Left = function (val) { |
1036 | 1024 | return new Either.fn.init(val, false) |
1037 | 1025 | } |
1038 | 1026 |
|
|
1133 | 1121 | Either.isInstance = isInstance(TYPES_NAMES.Either) |
1134 | 1122 | Either.isOfType = isOfType(TYPES_NAMES.Either) |
1135 | 1123 |
|
1136 | | - var Reader = root.Reader = function (fn) { |
| 1124 | + var Reader = Monet.Reader = function (fn) { |
1137 | 1125 | return new Reader.fn.init(fn) |
1138 | 1126 | } |
1139 | 1127 |
|
|
1191 | 1179 | Reader.isInstance = isInstance(TYPES_NAMES.Reader) |
1192 | 1180 | Reader.isOfType = isOfType(TYPES_NAMES.Reader) |
1193 | 1181 |
|
1194 | | - var Free = root.Free = {} |
| 1182 | + var Free = Monet.Free = {} |
1195 | 1183 |
|
1196 | | - var Suspend = Free.Suspend = root.Suspend = function (functor) { |
| 1184 | + var Suspend = Free.Suspend = Monet.Suspend = function (functor) { |
1197 | 1185 | return new Free.fn.init(functor, true) |
1198 | 1186 | } |
1199 | | - var Return = Free.Return = root.Return = function (val) { |
| 1187 | + var Return = Free.Return = Monet.Return = function (val) { |
1200 | 1188 | return new Free.fn.init(val, false) |
1201 | 1189 | } |
1202 | 1190 |
|
|
1285 | 1273 | return new Identity.fn.init(a) |
1286 | 1274 | } |
1287 | 1275 |
|
1288 | | - root.Identity = Identity |
| 1276 | + Monet.Identity = Identity |
1289 | 1277 |
|
1290 | 1278 | Identity.of = function (a) { |
1291 | 1279 | return new Identity(a) |
|
1330 | 1318 | return List(this.get(), Nil) |
1331 | 1319 | }, |
1332 | 1320 | toSet: function () { |
1333 | | - if (!rootGlobalObject.Set) { |
1334 | | - throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.') |
1335 | | - } |
1336 | 1321 | return new Set(this) |
1337 | 1322 | } |
1338 | 1323 | } |
|
1429 | 1414 |
|
1430 | 1415 | function makeIterable(type) { |
1431 | 1416 | if (isFunction(type.prototype.toArray)) { |
1432 | | - if (!rootGlobalObject.Symbol) { |
1433 | | - // eslint-disable-next-line no-console |
1434 | | - console.error(new Error('Provide polyfill or use up to date browser/node version to use "Iterable" protocol.')) |
1435 | | - } |
1436 | 1417 | type.prototype[Symbol.iterator] = function () { |
1437 | 1418 | return this.toArray()[Symbol.iterator]() |
1438 | 1419 | } |
|
1470 | 1451 | decorate(Free) |
1471 | 1452 | decorate(Identity) |
1472 | 1453 |
|
1473 | | - return Maybe.fromNull(rootGlobalObject) |
1474 | | - .filter(function (rootObj) { return rootObj.useMonetGlobalObject }) |
1475 | | - .cata(function () { return assign(Monet, root) }, function (rootObj) { |
1476 | | - assign(rootObj, root) |
1477 | | - rootObj.Monet = Monet |
1478 | | - return Monet |
1479 | | - }) |
| 1454 | + return Monet |
1480 | 1455 | })) |
0 commit comments