vviinn-widgets 2.16.1 → 2.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vviinn-widgets/Array-bdfc75db.js +4870 -0
- package/dist/vviinn-widgets/Handler-edcb46f4.js +1422 -0
- package/dist/vviinn-widgets/NonEmptyArray-947ab7b3.js +4411 -0
- package/dist/vviinn-widgets/app-globals-76b20e61.js +8 -0
- package/dist/vviinn-widgets/cropper-handler.entry.js +23 -0
- package/dist/vviinn-widgets/css-shim-f0027935.js +4 -0
- package/dist/{esm/customized-slots-01387ced.js → vviinn-widgets/customized-slots-9c14bb69.js} +1 -1
- package/dist/vviinn-widgets/dom-db0073f0.js +73 -0
- package/dist/vviinn-widgets/highlight-box.entry.js +41 -0
- package/dist/{collection/components/image-search/image-view/image-cropper/image-cropper.js → vviinn-widgets/image-cropper.entry.js} +33 -66
- package/dist/{esm/index-492f97b7.js → vviinn-widgets/imageSearch.store-77991a45.js} +11972 -15280
- package/dist/{esm/index-84a46578.js → vviinn-widgets/index-34d88ba6.js} +4 -2
- package/dist/vviinn-widgets/index-6c6de682.js +3857 -0
- package/dist/vviinn-widgets/index-e80ee507.js +3010 -0
- package/dist/vviinn-widgets/index.esm.js +1 -0
- package/dist/vviinn-widgets/number-171db649.js +1499 -0
- package/dist/vviinn-widgets/search-filters.entry.js +76 -0
- package/dist/vviinn-widgets/shadow-css-c1fdfa9f.js +389 -0
- package/dist/{esm → vviinn-widgets}/vviinn-button.entry.js +2 -2
- package/dist/{collection/components/vviinn-carousel/vviinn-carousel.js → vviinn-widgets/vviinn-carousel.entry.js} +18 -113
- package/dist/vviinn-widgets/vviinn-detected-object.entry.js +54 -0
- package/dist/vviinn-widgets/vviinn-empty-results.entry.js +16 -0
- package/dist/vviinn-widgets/vviinn-error.entry.js +15 -0
- package/dist/vviinn-widgets/vviinn-example-image.entry.js +43 -0
- package/dist/vviinn-widgets/vviinn-example-images.entry.js +33 -0
- package/dist/vviinn-widgets/vviinn-image-selector.entry.js +31 -0
- package/dist/vviinn-widgets/vviinn-image-view.entry.js +55 -0
- package/dist/vviinn-widgets/vviinn-modal.entry.js +30 -0
- package/dist/vviinn-widgets/vviinn-onboarding-card-1.entry.js +21 -0
- package/dist/vviinn-widgets/vviinn-onboarding-card-2.entry.js +21 -0
- package/dist/vviinn-widgets/vviinn-onboarding-card-3.entry.js +21 -0
- package/dist/vviinn-widgets/vviinn-onboarding.entry.js +20 -0
- package/dist/vviinn-widgets/vviinn-overlay.entry.js +15 -0
- package/dist/vviinn-widgets/vviinn-overlayed-modal.entry.js +18 -0
- package/dist/vviinn-widgets/vviinn-preloader.entry.js +25 -0
- package/dist/vviinn-widgets/vviinn-privacy-badge.entry.js +20 -0
- package/dist/vviinn-widgets/vviinn-product-card.entry.js +189 -0
- package/dist/{esm → vviinn-widgets}/vviinn-recommendations-sidebar.entry.js +2 -2
- package/dist/vviinn-widgets/vviinn-server-error.entry.js +16 -0
- package/dist/vviinn-widgets/vviinn-slide.entry.js +15 -0
- package/dist/vviinn-widgets/vviinn-slider.entry.js +120 -0
- package/dist/vviinn-widgets/vviinn-teaser.entry.js +20 -0
- package/dist/{esm → vviinn-widgets}/vviinn-vpr-button.entry.js +2 -2
- package/dist/vviinn-widgets/vviinn-vpr-widget.entry.js +4609 -0
- package/dist/{esm → vviinn-widgets}/vviinn-vps-button.entry.js +3 -3
- package/dist/vviinn-widgets/vviinn-vps-widget.entry.js +199 -0
- package/dist/vviinn-widgets/vviinn-widgets.css +6 -1
- package/dist/vviinn-widgets/vviinn-widgets.esm.js +125 -1
- package/dist/vviinn-widgets/vviinn-wrong-format.entry.js +16 -0
- package/package.json +1 -1
- package/www/build/Array-bdfc75db.js +4870 -0
- package/www/build/Handler-edcb46f4.js +1422 -0
- package/www/build/NonEmptyArray-947ab7b3.js +4411 -0
- package/www/build/app-globals-76b20e61.js +8 -0
- package/www/build/cropper-handler.entry.js +23 -0
- package/www/build/css-shim-f0027935.js +4 -0
- package/{dist/cjs/customized-slots-84e1c444.js → www/build/customized-slots-9c14bb69.js} +3 -6
- package/www/build/dom-db0073f0.js +73 -0
- package/www/build/highlight-box.entry.js +41 -0
- package/www/build/image-cropper.entry.js +124 -0
- package/{dist/cjs/index-4ea3a37f.js → www/build/imageSearch.store-77991a45.js} +11302 -14660
- package/{dist/collection/components/vviinn-icons/index.js → www/build/index-34d88ba6.js} +14 -11
- package/www/build/index-6c6de682.js +3857 -0
- package/www/build/index-e80ee507.js +3010 -0
- package/www/build/index.esm.js +1 -0
- package/www/build/number-171db649.js +1499 -0
- package/www/build/search-filters.entry.js +76 -0
- package/www/build/shadow-css-c1fdfa9f.js +389 -0
- package/{dist/cjs/vviinn-button.cjs.entry.js → www/build/vviinn-button.entry.js} +5 -9
- package/www/build/vviinn-carousel.entry.js +210 -0
- package/www/build/vviinn-detected-object.entry.js +54 -0
- package/www/build/vviinn-empty-results.entry.js +16 -0
- package/www/build/vviinn-error.entry.js +15 -0
- package/www/build/vviinn-example-image.entry.js +43 -0
- package/www/build/vviinn-example-images.entry.js +33 -0
- package/www/build/vviinn-image-selector.entry.js +31 -0
- package/www/build/vviinn-image-view.entry.js +55 -0
- package/www/build/vviinn-modal.entry.js +30 -0
- package/www/build/vviinn-onboarding-card-1.entry.js +21 -0
- package/www/build/vviinn-onboarding-card-2.entry.js +21 -0
- package/www/build/vviinn-onboarding-card-3.entry.js +21 -0
- package/www/build/vviinn-onboarding.entry.js +20 -0
- package/www/build/vviinn-overlay.entry.js +15 -0
- package/www/build/vviinn-overlayed-modal.entry.js +18 -0
- package/www/build/vviinn-preloader.entry.js +25 -0
- package/www/build/vviinn-privacy-badge.entry.js +20 -0
- package/www/build/vviinn-product-card.entry.js +189 -0
- package/{dist/cjs/vviinn-recommendations-sidebar.cjs.entry.js → www/build/vviinn-recommendations-sidebar.entry.js} +8 -12
- package/www/build/vviinn-server-error.entry.js +16 -0
- package/www/build/vviinn-slide.entry.js +15 -0
- package/www/build/vviinn-slider.entry.js +120 -0
- package/www/build/vviinn-teaser.entry.js +20 -0
- package/{dist/cjs/vviinn-vpr-button.cjs.entry.js → www/build/vviinn-vpr-button.entry.js} +5 -9
- package/www/build/vviinn-vpr-widget.entry.js +4609 -0
- package/www/build/vviinn-vps-button.entry.js +41 -0
- package/www/build/vviinn-vps-widget.entry.js +199 -0
- package/www/build/vviinn-widgets.css +6 -1
- package/www/build/vviinn-widgets.esm.js +125 -1
- package/www/build/vviinn-wrong-format.entry.js +16 -0
- package/www/index.html +10 -1
- package/dist/cjs/cropper-handler_27.cjs.entry.js +0 -1185
- package/dist/cjs/index-1077e27c.js +0 -1365
- package/dist/cjs/index-b2b8f092.js +0 -39
- package/dist/cjs/index.cjs.js +0 -2
- package/dist/cjs/loader.cjs.js +0 -21
- package/dist/cjs/vviinn-carousel_2.cjs.entry.js +0 -1022
- package/dist/cjs/vviinn-vps-button.cjs.entry.js +0 -45
- package/dist/cjs/vviinn-widgets.cjs.js +0 -19
- package/dist/collection/Image/error.js +0 -14
- package/dist/collection/Image/form.js +0 -5
- package/dist/collection/Image/fromFile.js +0 -20
- package/dist/collection/Image/imageToB64.js +0 -9
- package/dist/collection/Image/index.js +0 -0
- package/dist/collection/Image/renderPromise.js +0 -6
- package/dist/collection/Image/resizeImage.js +0 -28
- package/dist/collection/Image/sizing.js +0 -39
- package/dist/collection/Image/toFile.js +0 -17
- package/dist/collection/analytics/GAnalytics.js +0 -32
- package/dist/collection/analytics/GeneralAnalytics.js +0 -9
- package/dist/collection/analytics/GtagAnalytics.js +0 -35
- package/dist/collection/analytics/ProductAnalytics.js +0 -1
- package/dist/collection/campaign/Campaign.js +0 -8
- package/dist/collection/campaign/CampaignService.js +0 -5
- package/dist/collection/campaign/VCSCampaign.js +0 -1
- package/dist/collection/campaign/VCSCampaignResponse.js +0 -1
- package/dist/collection/campaign/VCSCampaignService.js +0 -7
- package/dist/collection/campaign/VPRCampaignResponse.js +0 -1
- package/dist/collection/campaign/VPRCampaignService.js +0 -7
- package/dist/collection/collection-manifest.json +0 -44
- package/dist/collection/components/customized-slots.js +0 -47
- package/dist/collection/components/image-search/image-view/highlight-box/highlight-box.css +0 -71
- package/dist/collection/components/image-search/image-view/highlight-box/highlight-box.js +0 -25
- package/dist/collection/components/image-search/image-view/image-cropper/cropper-handler/cropper-handler.css +0 -49
- package/dist/collection/components/image-search/image-view/image-cropper/cropper-handler/cropper-handler.js +0 -60
- package/dist/collection/components/image-search/image-view/image-cropper/image-cropper.css +0 -33
- package/dist/collection/components/image-search/search-filters/search-filters.css +0 -120
- package/dist/collection/components/image-search/search-filters/search-filters.js +0 -125
- package/dist/collection/components/vviinn-button/vviinn-button.css +0 -44
- package/dist/collection/components/vviinn-button/vviinn-button.js +0 -45
- package/dist/collection/components/vviinn-carousel/vviinn-carousel.css +0 -142
- package/dist/collection/components/vviinn-error/vviinn-empty-results/vviinn-empty-results.css +0 -7
- package/dist/collection/components/vviinn-error/vviinn-empty-results/vviinn-empty-results.js +0 -36
- package/dist/collection/components/vviinn-error/vviinn-error.css +0 -38
- package/dist/collection/components/vviinn-error/vviinn-error.js +0 -18
- package/dist/collection/components/vviinn-error/vviinn-server-error/vviinn-server-error.css +0 -3
- package/dist/collection/components/vviinn-error/vviinn-server-error/vviinn-server-error.js +0 -34
- package/dist/collection/components/vviinn-error/vviinn-wrong-format/vviinn-wrong-format.css +0 -3
- package/dist/collection/components/vviinn-error/vviinn-wrong-format/vviinn-wrong-format.js +0 -34
- package/dist/collection/components/vviinn-example-images/vviinn-example-image/vviinn-example-image.css +0 -37
- package/dist/collection/components/vviinn-example-images/vviinn-example-image/vviinn-example-image.js +0 -134
- package/dist/collection/components/vviinn-example-images/vviinn-example-images.css +0 -19
- package/dist/collection/components/vviinn-example-images/vviinn-example-images.js +0 -85
- package/dist/collection/components/vviinn-image-selector/vviinn-image-selector.css +0 -26
- package/dist/collection/components/vviinn-image-selector/vviinn-image-selector.js +0 -64
- package/dist/collection/components/vviinn-image-view/vviinn-detected-object/vviinn-detected-object.css +0 -47
- package/dist/collection/components/vviinn-image-view/vviinn-detected-object/vviinn-detected-object.js +0 -100
- package/dist/collection/components/vviinn-image-view/vviinn-image-view.css +0 -31
- package/dist/collection/components/vviinn-image-view/vviinn-image-view.js +0 -57
- package/dist/collection/components/vviinn-modal/vviinn-modal.css +0 -106
- package/dist/collection/components/vviinn-modal/vviinn-modal.js +0 -98
- package/dist/collection/components/vviinn-onboarding/onboarding-cards/onboarding-card.css +0 -41
- package/dist/collection/components/vviinn-onboarding/onboarding-cards/vviinn-onboarding-card-1/vviinn-onboarding-card-1.js +0 -26
- package/dist/collection/components/vviinn-onboarding/onboarding-cards/vviinn-onboarding-card-2/vviinn-onboarding-card-2.js +0 -26
- package/dist/collection/components/vviinn-onboarding/onboarding-cards/vviinn-onboarding-card-3/vviinn-onboarding-card-3.js +0 -26
- package/dist/collection/components/vviinn-onboarding/vviinn-onboarding.css +0 -58
- package/dist/collection/components/vviinn-onboarding/vviinn-onboarding.js +0 -28
- package/dist/collection/components/vviinn-overlay/vviinn-overlay.css +0 -33
- package/dist/collection/components/vviinn-overlay/vviinn-overlay.js +0 -15
- package/dist/collection/components/vviinn-overlayed-modal/vviinn-overlayed-modal.css +0 -30
- package/dist/collection/components/vviinn-overlayed-modal/vviinn-overlayed-modal.js +0 -71
- package/dist/collection/components/vviinn-preloader/vviinn-preloader.css +0 -37
- package/dist/collection/components/vviinn-preloader/vviinn-preloader.js +0 -20
- package/dist/collection/components/vviinn-privacy-badge/vviinn-privacy-badge.css +0 -19
- package/dist/collection/components/vviinn-privacy-badge/vviinn-privacy-badge.js +0 -27
- package/dist/collection/components/vviinn-product-card/render-helpers.js +0 -34
- package/dist/collection/components/vviinn-product-card/stories/args.js +0 -73
- package/dist/collection/components/vviinn-product-card/stories/decorators.js +0 -51
- package/dist/collection/components/vviinn-product-card/stories/vviinn-product-card.stories.js +0 -105
- package/dist/collection/components/vviinn-product-card/vviinn-product-card.css +0 -95
- package/dist/collection/components/vviinn-product-card/vviinn-product-card.js +0 -463
- package/dist/collection/components/vviinn-slider/arrow.js +0 -11
- package/dist/collection/components/vviinn-slider/vviinn-slide/vviinn-slide.css +0 -4
- package/dist/collection/components/vviinn-slider/vviinn-slide/vviinn-slide.js +0 -15
- package/dist/collection/components/vviinn-slider/vviinn-slider.css +0 -110
- package/dist/collection/components/vviinn-slider/vviinn-slider.js +0 -181
- package/dist/collection/components/vviinn-teaser/vviinn-teaser.css +0 -14
- package/dist/collection/components/vviinn-teaser/vviinn-teaser.js +0 -29
- package/dist/collection/components/vviinn-vpr-button/recommendations-sidebar/recommendations-sidebar.css +0 -244
- package/dist/collection/components/vviinn-vpr-button/recommendations-sidebar/recommendations-sidebar.js +0 -263
- package/dist/collection/components/vviinn-vpr-button/stories/args.js +0 -217
- package/dist/collection/components/vviinn-vpr-button/stories/vviinn-vpr-button.stories.js +0 -90
- package/dist/collection/components/vviinn-vpr-button/vviinn-vpr-button.css +0 -8
- package/dist/collection/components/vviinn-vpr-button/vviinn-vpr-button.js +0 -243
- package/dist/collection/components/vviinn-vpr-widget/stories/args.js +0 -197
- package/dist/collection/components/vviinn-vpr-widget/stories/decorators.js +0 -29
- package/dist/collection/components/vviinn-vpr-widget/stories/vviinn-vpr-widget.stories.js +0 -210
- package/dist/collection/components/vviinn-vpr-widget/token-helpers.js +0 -11
- package/dist/collection/components/vviinn-vpr-widget/vviinn-vpr-vidget.js +0 -534
- package/dist/collection/components/vviinn-vpr-widget/vviinn-vpr-widget.css +0 -79
- package/dist/collection/components/vviinn-vps-button/stories/vviinn-vps-button.stories.js +0 -36
- package/dist/collection/components/vviinn-vps-button/vviinn-vps-button.css +0 -9
- package/dist/collection/components/vviinn-vps-button/vviinn-vps-button.js +0 -218
- package/dist/collection/components/vviinn-vps-widget/stories/vviinn-vps-widget.stories.js +0 -38
- package/dist/collection/components/vviinn-vps-widget/vviinn-vps-widget.css +0 -355
- package/dist/collection/components/vviinn-vps-widget/vviinn-vps-widget.js +0 -424
- package/dist/collection/cropper/Cropper.js +0 -1
- package/dist/collection/cropper/Handler.js +0 -61
- package/dist/collection/dom/index.js +0 -3
- package/dist/collection/error.js +0 -14
- package/dist/collection/file/index.js +0 -4
- package/dist/collection/geometry/Clip.js +0 -14
- package/dist/collection/geometry/Point.js +0 -32
- package/dist/collection/geometry/Rectangle.js +0 -95
- package/dist/collection/geometry/RectangleAlt.js +0 -1
- package/dist/collection/geometry/Sized.js +0 -8
- package/dist/collection/global.js +0 -4
- package/dist/collection/index.js +0 -1
- package/dist/collection/interfaces/generated.js +0 -5
- package/dist/collection/interfaces/recommendation.js +0 -1
- package/dist/collection/network/apiClient.js +0 -9
- package/dist/collection/network/ion/File.js +0 -14
- package/dist/collection/network/ion/Form.js +0 -64
- package/dist/collection/network/ion/Link.js +0 -8
- package/dist/collection/network/ion/ValueObject.js +0 -23
- package/dist/collection/network/request.js +0 -19
- package/dist/collection/network/utils.js +0 -37
- package/dist/collection/openApi/index.js +0 -27
- package/dist/collection/recommendation/events.js +0 -1
- package/dist/collection/recommendation/recommendation.js +0 -1
- package/dist/collection/searchSession/searchSession.js +0 -31
- package/dist/collection/sentry.js +0 -14
- package/dist/collection/slider/GridMode.js +0 -1
- package/dist/collection/store/file-processing.js +0 -13
- package/dist/collection/store/imageSearch.store.js +0 -133
- package/dist/collection/store/store.js +0 -3
- package/dist/collection/store/tracking.store.js +0 -3
- package/dist/collection/stories/image-selector.stories.js +0 -6
- package/dist/collection/stories/image-view.stories.js +0 -6
- package/dist/collection/stories/modal.stories.js +0 -12
- package/dist/collection/stories/onboarding.stories.js +0 -11
- package/dist/collection/stories/overlay.stories.js +0 -5
- package/dist/collection/stories/overlayedModal.stories.js +0 -8
- package/dist/collection/stories/privacy-badge.stories.js +0 -11
- package/dist/collection/stories/slider.stories.js +0 -17
- package/dist/collection/stories/teaser.stories.js +0 -5
- package/dist/collection/stories/vps-widget.stories.js +0 -47
- package/dist/collection/stories/vviinn-product.stories.js +0 -19
- package/dist/collection/tracking/event.js +0 -3
- package/dist/collection/tracking/filter.js +0 -5
- package/dist/collection/tracking/index.js +0 -13
- package/dist/collection/tracking/models.js +0 -6
- package/dist/collection/tracking/product.js +0 -18
- package/dist/collection/tracking/search.js +0 -5
- package/dist/collection/tracking/widget.js +0 -10
- package/dist/collection/utils/collections/collectionsUtils.js +0 -5
- package/dist/collection/utils/either.js +0 -3
- package/dist/collection/utils/enum/enumUtils.js +0 -3
- package/dist/collection/utils/event/Events.js +0 -1
- package/dist/collection/utils/number/index.js +0 -4
- package/dist/collection/utils/option/option.js +0 -4
- package/dist/collection/utils/semigroup/semigroupDiff.js +0 -6
- package/dist/collection/utils/token/tokenUtils.js +0 -9
- package/dist/esm/cropper-handler_27.entry.js +0 -1155
- package/dist/esm/index-65670ecf.js +0 -1335
- package/dist/esm/index.js +0 -1
- package/dist/esm/loader.js +0 -17
- package/dist/esm/polyfills/core-js.js +0 -11
- package/dist/esm/polyfills/css-shim.js +0 -1
- package/dist/esm/polyfills/dom.js +0 -79
- package/dist/esm/polyfills/es5-html-element.js +0 -1
- package/dist/esm/polyfills/index.js +0 -34
- package/dist/esm/polyfills/system.js +0 -6
- package/dist/esm/vviinn-carousel_2.entry.js +0 -1017
- package/dist/esm/vviinn-widgets.js +0 -17
- package/dist/index.cjs.js +0 -1
- package/dist/index.js +0 -1
- package/dist/loader/cdn.js +0 -3
- package/dist/loader/index.cjs.js +0 -3
- package/dist/loader/index.d.ts +0 -12
- package/dist/loader/index.es2017.js +0 -3
- package/dist/loader/index.js +0 -4
- package/dist/loader/package.json +0 -10
- package/dist/vviinn-widgets/p-18bb4ada.entry.js +0 -1
- package/dist/vviinn-widgets/p-249af9d5.entry.js +0 -1
- package/dist/vviinn-widgets/p-2573d0c3.js +0 -1
- package/dist/vviinn-widgets/p-3e92671c.entry.js +0 -1
- package/dist/vviinn-widgets/p-90742d1c.js +0 -1
- package/dist/vviinn-widgets/p-9194527e.js +0 -1
- package/dist/vviinn-widgets/p-99a98699.entry.js +0 -1
- package/dist/vviinn-widgets/p-af321db4.js +0 -1
- package/dist/vviinn-widgets/p-af5be84d.entry.js +0 -1
- package/dist/vviinn-widgets/p-d57f4a28.entry.js +0 -1
- package/www/build/p-001a9e47.js +0 -1
- package/www/build/p-18bb4ada.entry.js +0 -1
- package/www/build/p-249af9d5.entry.js +0 -1
- package/www/build/p-2573d0c3.js +0 -1
- package/www/build/p-3e92671c.entry.js +0 -1
- package/www/build/p-90742d1c.js +0 -1
- package/www/build/p-9194527e.js +0 -1
- package/www/build/p-99a98699.entry.js +0 -1
- package/www/build/p-a67898be.css +0 -1
- package/www/build/p-af321db4.js +0 -1
- package/www/build/p-af5be84d.entry.js +0 -1
- package/www/build/p-d57f4a28.entry.js +0 -1
|
@@ -0,0 +1,4870 @@
|
|
|
1
|
+
import { c as createCommonjsModule, g as getDefaultExportFromCjs, a as commonjsGlobal, i as internal, R as ReadonlyNonEmptyArray, _ as _function, S as Separated, E as Eq, O as Ord, F as Functor, A as Apply, C as Chain, Z as Zero, W as Witherable, b as FromEither, N as NonEmptyArray } from './NonEmptyArray-947ab7b3.js';
|
|
2
|
+
|
|
3
|
+
var number = createCommonjsModule(function (module, exports) {
|
|
4
|
+
"use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Field = exports.MonoidProduct = exports.MonoidSum = exports.SemigroupProduct = exports.SemigroupSum = exports.MagmaSub = exports.Show = exports.Bounded = exports.Ord = exports.Eq = exports.isNumber = void 0;
|
|
7
|
+
// -------------------------------------------------------------------------------------
|
|
8
|
+
// refinements
|
|
9
|
+
// -------------------------------------------------------------------------------------
|
|
10
|
+
/**
|
|
11
|
+
* @category refinements
|
|
12
|
+
* @since 2.11.0
|
|
13
|
+
*/
|
|
14
|
+
var isNumber = function (u) { return typeof u === 'number'; };
|
|
15
|
+
exports.isNumber = isNumber;
|
|
16
|
+
// -------------------------------------------------------------------------------------
|
|
17
|
+
// instances
|
|
18
|
+
// -------------------------------------------------------------------------------------
|
|
19
|
+
/**
|
|
20
|
+
* @category instances
|
|
21
|
+
* @since 2.10.0
|
|
22
|
+
*/
|
|
23
|
+
exports.Eq = {
|
|
24
|
+
equals: function (first, second) { return first === second; }
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @category instances
|
|
28
|
+
* @since 2.10.0
|
|
29
|
+
*/
|
|
30
|
+
exports.Ord = {
|
|
31
|
+
equals: exports.Eq.equals,
|
|
32
|
+
compare: function (first, second) { return (first < second ? -1 : first > second ? 1 : 0); }
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @category instances
|
|
36
|
+
* @since 2.10.0
|
|
37
|
+
*/
|
|
38
|
+
exports.Bounded = {
|
|
39
|
+
equals: exports.Eq.equals,
|
|
40
|
+
compare: exports.Ord.compare,
|
|
41
|
+
top: Infinity,
|
|
42
|
+
bottom: -Infinity
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @category instances
|
|
46
|
+
* @since 2.10.0
|
|
47
|
+
*/
|
|
48
|
+
exports.Show = {
|
|
49
|
+
show: function (n) { return JSON.stringify(n); }
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* @category instances
|
|
53
|
+
* @since 2.11.0
|
|
54
|
+
*/
|
|
55
|
+
exports.MagmaSub = {
|
|
56
|
+
concat: function (first, second) { return first - second; }
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* `number` semigroup under addition.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* import { SemigroupSum } from 'fp-ts/number'
|
|
63
|
+
*
|
|
64
|
+
* assert.deepStrictEqual(SemigroupSum.concat(2, 3), 5)
|
|
65
|
+
*
|
|
66
|
+
* @category instances
|
|
67
|
+
* @since 2.10.0
|
|
68
|
+
*/
|
|
69
|
+
exports.SemigroupSum = {
|
|
70
|
+
concat: function (first, second) { return first + second; }
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* `number` semigroup under multiplication.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* import { SemigroupProduct } from 'fp-ts/number'
|
|
77
|
+
*
|
|
78
|
+
* assert.deepStrictEqual(SemigroupProduct.concat(2, 3), 6)
|
|
79
|
+
*
|
|
80
|
+
* @category instances
|
|
81
|
+
* @since 2.10.0
|
|
82
|
+
*/
|
|
83
|
+
exports.SemigroupProduct = {
|
|
84
|
+
concat: function (first, second) { return first * second; }
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* `number` monoid under addition.
|
|
88
|
+
*
|
|
89
|
+
* The `empty` value is `0`.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* import { MonoidSum } from 'fp-ts/number'
|
|
93
|
+
*
|
|
94
|
+
* assert.deepStrictEqual(MonoidSum.concat(2, MonoidSum.empty), 2)
|
|
95
|
+
*
|
|
96
|
+
* @category instances
|
|
97
|
+
* @since 2.10.0
|
|
98
|
+
*/
|
|
99
|
+
exports.MonoidSum = {
|
|
100
|
+
concat: exports.SemigroupSum.concat,
|
|
101
|
+
empty: 0
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* `number` monoid under multiplication.
|
|
105
|
+
*
|
|
106
|
+
* The `empty` value is `1`.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* import { MonoidProduct } from 'fp-ts/number'
|
|
110
|
+
*
|
|
111
|
+
* assert.deepStrictEqual(MonoidProduct.concat(2, MonoidProduct.empty), 2)
|
|
112
|
+
*
|
|
113
|
+
* @category instances
|
|
114
|
+
* @since 2.10.0
|
|
115
|
+
*/
|
|
116
|
+
exports.MonoidProduct = {
|
|
117
|
+
concat: exports.SemigroupProduct.concat,
|
|
118
|
+
empty: 1
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* @category instances
|
|
122
|
+
* @since 2.10.0
|
|
123
|
+
*/
|
|
124
|
+
exports.Field = {
|
|
125
|
+
add: exports.SemigroupSum.concat,
|
|
126
|
+
zero: 0,
|
|
127
|
+
mul: exports.SemigroupProduct.concat,
|
|
128
|
+
one: 1,
|
|
129
|
+
sub: exports.MagmaSub.concat,
|
|
130
|
+
degree: function (_) { return 1; },
|
|
131
|
+
div: function (first, second) { return first / second; },
|
|
132
|
+
mod: function (first, second) { return first % second; }
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const number$1 = /*@__PURE__*/getDefaultExportFromCjs(number);
|
|
137
|
+
|
|
138
|
+
var ReadonlyArray = createCommonjsModule(function (module, exports) {
|
|
139
|
+
"use strict";
|
|
140
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
141
|
+
if (k2 === undefined) k2 = k;
|
|
142
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
143
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
144
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
145
|
+
}
|
|
146
|
+
Object.defineProperty(o, k2, desc);
|
|
147
|
+
}) : (function(o, m, k, k2) {
|
|
148
|
+
if (k2 === undefined) k2 = k;
|
|
149
|
+
o[k2] = m[k];
|
|
150
|
+
}));
|
|
151
|
+
var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
152
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
153
|
+
}) : function(o, v) {
|
|
154
|
+
o["default"] = v;
|
|
155
|
+
});
|
|
156
|
+
var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
|
|
157
|
+
if (mod && mod.__esModule) return mod;
|
|
158
|
+
var result = {};
|
|
159
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
160
|
+
__setModuleDefault(result, mod);
|
|
161
|
+
return result;
|
|
162
|
+
};
|
|
163
|
+
var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
|
|
164
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
165
|
+
if (ar || !(i in from)) {
|
|
166
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
167
|
+
ar[i] = from[i];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
171
|
+
};
|
|
172
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
173
|
+
exports.sort = exports.lefts = exports.rights = exports.reverse = exports.modifyAt = exports.deleteAt = exports.updateAt = exports.insertAt = exports.findLastIndex = exports.findLastMap = exports.findLast = exports.findFirstMap = exports.findFirst = exports.findIndex = exports.dropLeftWhile = exports.dropRight = exports.dropLeft = exports.spanLeft = exports.takeLeftWhile = exports.takeRight = exports.takeLeft = exports.init = exports.tail = exports.last = exports.head = exports.lookup = exports.isOutOfBound = exports.size = exports.scanRight = exports.scanLeft = exports.chainWithIndex = exports.foldRight = exports.matchRight = exports.matchRightW = exports.foldLeft = exports.matchLeft = exports.matchLeftW = exports.match = exports.matchW = exports.fromEither = exports.fromOption = exports.fromPredicate = exports.replicate = exports.makeBy = exports.appendW = exports.append = exports.prependW = exports.prepend = exports.isNonEmpty = exports.isEmpty = void 0;
|
|
174
|
+
exports.sequence = exports.traverse = exports.reduceRightWithIndex = exports.reduceRight = exports.reduceWithIndex = exports.foldMap = exports.reduce = exports.foldMapWithIndex = exports.duplicate = exports.extend = exports.filterWithIndex = exports.partitionMapWithIndex = exports.partitionMap = exports.partitionWithIndex = exports.partition = exports.compact = exports.filterMap = exports.filterMapWithIndex = exports.filter = exports.separate = exports.mapWithIndex = exports.map = exports.flatten = exports.chain = exports.ap = exports.alt = exports.altW = exports.zero = exports.of = exports._chainRecBreadthFirst = exports._chainRecDepthFirst = exports.difference = exports.intersection = exports.union = exports.concat = exports.concatW = exports.comprehension = exports.fromOptionK = exports.chunksOf = exports.splitAt = exports.chop = exports.sortBy = exports.uniq = exports.elem = exports.rotate = exports.intersperse = exports.prependAll = exports.unzip = exports.zip = exports.zipWith = void 0;
|
|
175
|
+
exports.toArray = exports.unsafeDeleteAt = exports.unsafeUpdateAt = exports.unsafeInsertAt = exports.fromEitherK = exports.FromEither = exports.filterE = exports.Witherable = exports.ChainRecBreadthFirst = exports.chainRecBreadthFirst = exports.ChainRecDepthFirst = exports.chainRecDepthFirst = exports.TraversableWithIndex = exports.Traversable = exports.FoldableWithIndex = exports.Foldable = exports.FilterableWithIndex = exports.Filterable = exports.Compactable = exports.Extend = exports.Alternative = exports.guard = exports.Zero = exports.Alt = exports.Unfoldable = exports.chainFirst = exports.Monad = exports.Chain = exports.Applicative = exports.apSecond = exports.apFirst = exports.Apply = exports.FunctorWithIndex = exports.Pointed = exports.flap = exports.Functor = exports.getDifferenceMagma = exports.getIntersectionSemigroup = exports.getUnionMonoid = exports.getUnionSemigroup = exports.getOrd = exports.getEq = exports.getMonoid = exports.getSemigroup = exports.getShow = exports.URI = exports.unfold = exports.wilt = exports.wither = exports.traverseWithIndex = void 0;
|
|
176
|
+
exports.readonlyArray = exports.prependToAll = exports.snoc = exports.cons = exports.range = exports.apS = exports.bind = exports.bindTo = exports.Do = exports.intercalate = exports.exists = exports.some = exports.every = exports.empty = exports.fromArray = void 0;
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
var _ = __importStar(internal);
|
|
184
|
+
var N = __importStar(number);
|
|
185
|
+
|
|
186
|
+
var RNEA = __importStar(ReadonlyNonEmptyArray);
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
// -------------------------------------------------------------------------------------
|
|
191
|
+
// refinements
|
|
192
|
+
// -------------------------------------------------------------------------------------
|
|
193
|
+
/**
|
|
194
|
+
* Test whether a `ReadonlyArray` is empty.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* import { isEmpty } from 'fp-ts/ReadonlyArray'
|
|
198
|
+
*
|
|
199
|
+
* assert.strictEqual(isEmpty([]), true)
|
|
200
|
+
*
|
|
201
|
+
* @category refinements
|
|
202
|
+
* @since 2.5.0
|
|
203
|
+
*/
|
|
204
|
+
var isEmpty = function (as) { return as.length === 0; };
|
|
205
|
+
exports.isEmpty = isEmpty;
|
|
206
|
+
/**
|
|
207
|
+
* Test whether a `ReadonlyArray` is non empty.
|
|
208
|
+
*
|
|
209
|
+
* @category refinements
|
|
210
|
+
* @since 2.5.0
|
|
211
|
+
*/
|
|
212
|
+
exports.isNonEmpty = RNEA.isNonEmpty;
|
|
213
|
+
// -------------------------------------------------------------------------------------
|
|
214
|
+
// constructors
|
|
215
|
+
// -------------------------------------------------------------------------------------
|
|
216
|
+
/**
|
|
217
|
+
* Prepend an element to the front of a `ReadonlyArray`, creating a new `ReadonlyNonEmptyArray`.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* import { prepend } from 'fp-ts/ReadonlyArray'
|
|
221
|
+
* import { pipe } from 'fp-ts/function'
|
|
222
|
+
*
|
|
223
|
+
* assert.deepStrictEqual(pipe([2, 3, 4], prepend(1)), [1, 2, 3, 4])
|
|
224
|
+
*
|
|
225
|
+
* @category constructors
|
|
226
|
+
* @since 2.10.0
|
|
227
|
+
*/
|
|
228
|
+
exports.prepend = RNEA.prepend;
|
|
229
|
+
/**
|
|
230
|
+
* Less strict version of [`prepend`](#prepend).
|
|
231
|
+
*
|
|
232
|
+
* @category constructors
|
|
233
|
+
* @since 2.11.0
|
|
234
|
+
*/
|
|
235
|
+
exports.prependW = RNEA.prependW;
|
|
236
|
+
/**
|
|
237
|
+
* Append an element to the end of a `ReadonlyArray`, creating a new `ReadonlyNonEmptyArray`.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* import { append } from 'fp-ts/ReadonlyArray'
|
|
241
|
+
* import { pipe } from 'fp-ts/function'
|
|
242
|
+
*
|
|
243
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], append(4)), [1, 2, 3, 4])
|
|
244
|
+
*
|
|
245
|
+
* @category constructors
|
|
246
|
+
* @since 2.10.0
|
|
247
|
+
*/
|
|
248
|
+
exports.append = RNEA.append;
|
|
249
|
+
/**
|
|
250
|
+
* Less strict version of [`append`](#append).
|
|
251
|
+
*
|
|
252
|
+
* @category constructors
|
|
253
|
+
* @since 2.11.0
|
|
254
|
+
*/
|
|
255
|
+
exports.appendW = RNEA.appendW;
|
|
256
|
+
/**
|
|
257
|
+
* Return a `ReadonlyArray` of length `n` with element `i` initialized with `f(i)`.
|
|
258
|
+
*
|
|
259
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* import { makeBy } from 'fp-ts/ReadonlyArray'
|
|
263
|
+
*
|
|
264
|
+
* const double = (n: number): number => n * 2
|
|
265
|
+
* assert.deepStrictEqual(makeBy(5, double), [0, 2, 4, 6, 8])
|
|
266
|
+
*
|
|
267
|
+
* @category constructors
|
|
268
|
+
* @since 2.5.0
|
|
269
|
+
*/
|
|
270
|
+
var makeBy = function (n, f) { return (n <= 0 ? exports.empty : RNEA.makeBy(f)(n)); };
|
|
271
|
+
exports.makeBy = makeBy;
|
|
272
|
+
/**
|
|
273
|
+
* Create a `ReadonlyArray` containing a value repeated the specified number of times.
|
|
274
|
+
*
|
|
275
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* import { replicate } from 'fp-ts/ReadonlyArray'
|
|
279
|
+
*
|
|
280
|
+
* assert.deepStrictEqual(replicate(3, 'a'), ['a', 'a', 'a'])
|
|
281
|
+
*
|
|
282
|
+
* @category constructors
|
|
283
|
+
* @since 2.5.0
|
|
284
|
+
*/
|
|
285
|
+
var replicate = function (n, a) { return (0, exports.makeBy)(n, function () { return a; }); };
|
|
286
|
+
exports.replicate = replicate;
|
|
287
|
+
function fromPredicate(predicate) {
|
|
288
|
+
return function (a) { return (predicate(a) ? [a] : exports.empty); };
|
|
289
|
+
}
|
|
290
|
+
exports.fromPredicate = fromPredicate;
|
|
291
|
+
// -------------------------------------------------------------------------------------
|
|
292
|
+
// natural transformations
|
|
293
|
+
// -------------------------------------------------------------------------------------
|
|
294
|
+
/**
|
|
295
|
+
* @category natural transformations
|
|
296
|
+
* @since 2.11.0
|
|
297
|
+
*/
|
|
298
|
+
var fromOption = function (ma) { return (_.isNone(ma) ? exports.empty : [ma.value]); };
|
|
299
|
+
exports.fromOption = fromOption;
|
|
300
|
+
/**
|
|
301
|
+
* Transforms an `Either` to a `ReadonlyArray`.
|
|
302
|
+
*
|
|
303
|
+
* @category natural transformations
|
|
304
|
+
* @since 2.11.0
|
|
305
|
+
*/
|
|
306
|
+
var fromEither = function (e) { return (_.isLeft(e) ? exports.empty : [e.right]); };
|
|
307
|
+
exports.fromEither = fromEither;
|
|
308
|
+
// -------------------------------------------------------------------------------------
|
|
309
|
+
// destructors
|
|
310
|
+
// -------------------------------------------------------------------------------------
|
|
311
|
+
/**
|
|
312
|
+
* Less strict version of [`match`](#match).
|
|
313
|
+
*
|
|
314
|
+
* @category destructors
|
|
315
|
+
* @since 2.11.0
|
|
316
|
+
*/
|
|
317
|
+
var matchW = function (onEmpty, onNonEmpty) { return function (as) { return ((0, exports.isNonEmpty)(as) ? onNonEmpty(as) : onEmpty()); }; };
|
|
318
|
+
exports.matchW = matchW;
|
|
319
|
+
/**
|
|
320
|
+
* @category destructors
|
|
321
|
+
* @since 2.11.0
|
|
322
|
+
*/
|
|
323
|
+
exports.match = exports.matchW;
|
|
324
|
+
/**
|
|
325
|
+
* Less strict version of [`matchLeft`](#matchleft).
|
|
326
|
+
*
|
|
327
|
+
* @category destructors
|
|
328
|
+
* @since 2.11.0
|
|
329
|
+
*/
|
|
330
|
+
var matchLeftW = function (onEmpty, onNonEmpty) { return function (as) { return ((0, exports.isNonEmpty)(as) ? onNonEmpty(RNEA.head(as), RNEA.tail(as)) : onEmpty()); }; };
|
|
331
|
+
exports.matchLeftW = matchLeftW;
|
|
332
|
+
/**
|
|
333
|
+
* Break a `ReadonlyArray` into its first element and remaining elements.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* import { matchLeft } from 'fp-ts/ReadonlyArray'
|
|
337
|
+
*
|
|
338
|
+
* const len: <A>(as: ReadonlyArray<A>) => number = matchLeft(() => 0, (_, tail) => 1 + len(tail))
|
|
339
|
+
* assert.strictEqual(len([1, 2, 3]), 3)
|
|
340
|
+
*
|
|
341
|
+
* @category destructors
|
|
342
|
+
* @since 2.10.0
|
|
343
|
+
*/
|
|
344
|
+
exports.matchLeft = exports.matchLeftW;
|
|
345
|
+
/**
|
|
346
|
+
* Alias of [`matchLeft`](#matchleft).
|
|
347
|
+
*
|
|
348
|
+
* @category destructors
|
|
349
|
+
* @since 2.5.0
|
|
350
|
+
*/
|
|
351
|
+
exports.foldLeft = exports.matchLeft;
|
|
352
|
+
/**
|
|
353
|
+
* Less strict version of [`matchRight`](#matchright).
|
|
354
|
+
*
|
|
355
|
+
* @category destructors
|
|
356
|
+
* @since 2.11.0
|
|
357
|
+
*/
|
|
358
|
+
var matchRightW = function (onEmpty, onNonEmpty) { return function (as) { return ((0, exports.isNonEmpty)(as) ? onNonEmpty(RNEA.init(as), RNEA.last(as)) : onEmpty()); }; };
|
|
359
|
+
exports.matchRightW = matchRightW;
|
|
360
|
+
/**
|
|
361
|
+
* Break a `ReadonlyArray` into its initial elements and the last element.
|
|
362
|
+
*
|
|
363
|
+
* @category destructors
|
|
364
|
+
* @since 2.10.0
|
|
365
|
+
*/
|
|
366
|
+
exports.matchRight = exports.matchRightW;
|
|
367
|
+
/**
|
|
368
|
+
* Alias of [`matchRight`](#matchright).
|
|
369
|
+
*
|
|
370
|
+
* @category destructors
|
|
371
|
+
* @since 2.5.0
|
|
372
|
+
*/
|
|
373
|
+
exports.foldRight = exports.matchRight;
|
|
374
|
+
// -------------------------------------------------------------------------------------
|
|
375
|
+
// combinators
|
|
376
|
+
// -------------------------------------------------------------------------------------
|
|
377
|
+
/**
|
|
378
|
+
* @category combinators
|
|
379
|
+
* @since 2.7.0
|
|
380
|
+
*/
|
|
381
|
+
var chainWithIndex = function (f) { return function (as) {
|
|
382
|
+
if ((0, exports.isEmpty)(as)) {
|
|
383
|
+
return exports.empty;
|
|
384
|
+
}
|
|
385
|
+
var out = [];
|
|
386
|
+
for (var i = 0; i < as.length; i++) {
|
|
387
|
+
out.push.apply(out, f(i, as[i]));
|
|
388
|
+
}
|
|
389
|
+
return out;
|
|
390
|
+
}; };
|
|
391
|
+
exports.chainWithIndex = chainWithIndex;
|
|
392
|
+
/**
|
|
393
|
+
* Same as `reduce` but it carries over the intermediate steps.
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* import { scanLeft } from 'fp-ts/ReadonlyArray'
|
|
397
|
+
*
|
|
398
|
+
* assert.deepStrictEqual(scanLeft(10, (b, a: number) => b - a)([1, 2, 3]), [10, 9, 7, 4])
|
|
399
|
+
*
|
|
400
|
+
* @category combinators
|
|
401
|
+
* @since 2.5.0
|
|
402
|
+
*/
|
|
403
|
+
var scanLeft = function (b, f) { return function (as) {
|
|
404
|
+
var len = as.length;
|
|
405
|
+
var out = new Array(len + 1);
|
|
406
|
+
out[0] = b;
|
|
407
|
+
for (var i = 0; i < len; i++) {
|
|
408
|
+
out[i + 1] = f(out[i], as[i]);
|
|
409
|
+
}
|
|
410
|
+
return out;
|
|
411
|
+
}; };
|
|
412
|
+
exports.scanLeft = scanLeft;
|
|
413
|
+
/**
|
|
414
|
+
* Fold an array from the right, keeping all intermediate results instead of only the final result
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* import { scanRight } from 'fp-ts/ReadonlyArray'
|
|
418
|
+
*
|
|
419
|
+
* assert.deepStrictEqual(scanRight(10, (a: number, b) => b - a)([1, 2, 3]), [4, 5, 7, 10])
|
|
420
|
+
*
|
|
421
|
+
* @category combinators
|
|
422
|
+
* @since 2.5.0
|
|
423
|
+
*/
|
|
424
|
+
var scanRight = function (b, f) { return function (as) {
|
|
425
|
+
var len = as.length;
|
|
426
|
+
var out = new Array(len + 1);
|
|
427
|
+
out[len] = b;
|
|
428
|
+
for (var i = len - 1; i >= 0; i--) {
|
|
429
|
+
out[i] = f(as[i], out[i + 1]);
|
|
430
|
+
}
|
|
431
|
+
return out;
|
|
432
|
+
}; };
|
|
433
|
+
exports.scanRight = scanRight;
|
|
434
|
+
/**
|
|
435
|
+
* Calculate the number of elements in a `ReadonlyArray`.
|
|
436
|
+
*
|
|
437
|
+
* @since 2.10.0
|
|
438
|
+
*/
|
|
439
|
+
var size = function (as) { return as.length; };
|
|
440
|
+
exports.size = size;
|
|
441
|
+
/**
|
|
442
|
+
* Test whether an array contains a particular index
|
|
443
|
+
*
|
|
444
|
+
* @since 2.5.0
|
|
445
|
+
*/
|
|
446
|
+
exports.isOutOfBound = RNEA.isOutOfBound;
|
|
447
|
+
function lookup(i, as) {
|
|
448
|
+
return as === undefined ? function (as) { return lookup(i, as); } : (0, exports.isOutOfBound)(i, as) ? _.none : _.some(as[i]);
|
|
449
|
+
}
|
|
450
|
+
exports.lookup = lookup;
|
|
451
|
+
/**
|
|
452
|
+
* Get the first element in an array, or `None` if the array is empty
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* import { head } from 'fp-ts/ReadonlyArray'
|
|
456
|
+
* import { some, none } from 'fp-ts/Option'
|
|
457
|
+
*
|
|
458
|
+
* assert.deepStrictEqual(head([1, 2, 3]), some(1))
|
|
459
|
+
* assert.deepStrictEqual(head([]), none)
|
|
460
|
+
*
|
|
461
|
+
* @since 2.5.0
|
|
462
|
+
*/
|
|
463
|
+
var head = function (as) { return ((0, exports.isNonEmpty)(as) ? _.some(RNEA.head(as)) : _.none); };
|
|
464
|
+
exports.head = head;
|
|
465
|
+
/**
|
|
466
|
+
* Get the last element in an array, or `None` if the array is empty
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* import { last } from 'fp-ts/ReadonlyArray'
|
|
470
|
+
* import { some, none } from 'fp-ts/Option'
|
|
471
|
+
*
|
|
472
|
+
* assert.deepStrictEqual(last([1, 2, 3]), some(3))
|
|
473
|
+
* assert.deepStrictEqual(last([]), none)
|
|
474
|
+
*
|
|
475
|
+
* @since 2.5.0
|
|
476
|
+
*/
|
|
477
|
+
var last = function (as) { return ((0, exports.isNonEmpty)(as) ? _.some(RNEA.last(as)) : _.none); };
|
|
478
|
+
exports.last = last;
|
|
479
|
+
/**
|
|
480
|
+
* Get all but the first element of an array, creating a new array, or `None` if the array is empty
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* import { tail } from 'fp-ts/ReadonlyArray'
|
|
484
|
+
* import { some, none } from 'fp-ts/Option'
|
|
485
|
+
*
|
|
486
|
+
* assert.deepStrictEqual(tail([1, 2, 3]), some([2, 3]))
|
|
487
|
+
* assert.deepStrictEqual(tail([]), none)
|
|
488
|
+
*
|
|
489
|
+
* @since 2.5.0
|
|
490
|
+
*/
|
|
491
|
+
var tail = function (as) {
|
|
492
|
+
return (0, exports.isNonEmpty)(as) ? _.some(RNEA.tail(as)) : _.none;
|
|
493
|
+
};
|
|
494
|
+
exports.tail = tail;
|
|
495
|
+
/**
|
|
496
|
+
* Get all but the last element of an array, creating a new array, or `None` if the array is empty
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* import { init } from 'fp-ts/ReadonlyArray'
|
|
500
|
+
* import { some, none } from 'fp-ts/Option'
|
|
501
|
+
*
|
|
502
|
+
* assert.deepStrictEqual(init([1, 2, 3]), some([1, 2]))
|
|
503
|
+
* assert.deepStrictEqual(init([]), none)
|
|
504
|
+
*
|
|
505
|
+
* @since 2.5.0
|
|
506
|
+
*/
|
|
507
|
+
var init = function (as) {
|
|
508
|
+
return (0, exports.isNonEmpty)(as) ? _.some(RNEA.init(as)) : _.none;
|
|
509
|
+
};
|
|
510
|
+
exports.init = init;
|
|
511
|
+
/**
|
|
512
|
+
* Keep only a max number of elements from the start of an `ReadonlyArray`, creating a new `ReadonlyArray`.
|
|
513
|
+
*
|
|
514
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* import * as RA from 'fp-ts/ReadonlyArray'
|
|
518
|
+
* import { pipe } from 'fp-ts/function'
|
|
519
|
+
*
|
|
520
|
+
* const input: ReadonlyArray<number> = [1, 2, 3]
|
|
521
|
+
* assert.deepStrictEqual(pipe(input, RA.takeLeft(2)), [1, 2])
|
|
522
|
+
*
|
|
523
|
+
* // out of bounds
|
|
524
|
+
* assert.strictEqual(pipe(input, RA.takeLeft(4)), input)
|
|
525
|
+
* assert.strictEqual(pipe(input, RA.takeLeft(-1)), input)
|
|
526
|
+
*
|
|
527
|
+
* @category combinators
|
|
528
|
+
* @since 2.5.0
|
|
529
|
+
*/
|
|
530
|
+
var takeLeft = function (n) { return function (as) {
|
|
531
|
+
return (0, exports.isOutOfBound)(n, as) ? as : n === 0 ? exports.empty : as.slice(0, n);
|
|
532
|
+
}; };
|
|
533
|
+
exports.takeLeft = takeLeft;
|
|
534
|
+
/**
|
|
535
|
+
* Keep only a max number of elements from the end of an `ReadonlyArray`, creating a new `ReadonlyArray`.
|
|
536
|
+
*
|
|
537
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* import * as RA from 'fp-ts/ReadonlyArray'
|
|
541
|
+
* import { pipe } from 'fp-ts/function'
|
|
542
|
+
*
|
|
543
|
+
* const input: ReadonlyArray<number> = [1, 2, 3]
|
|
544
|
+
* assert.deepStrictEqual(pipe(input, RA.takeRight(2)), [2, 3])
|
|
545
|
+
*
|
|
546
|
+
* // out of bounds
|
|
547
|
+
* assert.strictEqual(pipe(input, RA.takeRight(4)), input)
|
|
548
|
+
* assert.strictEqual(pipe(input, RA.takeRight(-1)), input)
|
|
549
|
+
*
|
|
550
|
+
* @category combinators
|
|
551
|
+
* @since 2.5.0
|
|
552
|
+
*/
|
|
553
|
+
var takeRight = function (n) { return function (as) {
|
|
554
|
+
return (0, exports.isOutOfBound)(n, as) ? as : n === 0 ? exports.empty : as.slice(-n);
|
|
555
|
+
}; };
|
|
556
|
+
exports.takeRight = takeRight;
|
|
557
|
+
function takeLeftWhile(predicate) {
|
|
558
|
+
return function (as) {
|
|
559
|
+
var out = [];
|
|
560
|
+
for (var _i = 0, as_1 = as; _i < as_1.length; _i++) {
|
|
561
|
+
var a = as_1[_i];
|
|
562
|
+
if (!predicate(a)) {
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
out.push(a);
|
|
566
|
+
}
|
|
567
|
+
var len = out.length;
|
|
568
|
+
return len === as.length ? as : len === 0 ? exports.empty : out;
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
exports.takeLeftWhile = takeLeftWhile;
|
|
572
|
+
var spanLeftIndex = function (as, predicate) {
|
|
573
|
+
var l = as.length;
|
|
574
|
+
var i = 0;
|
|
575
|
+
for (; i < l; i++) {
|
|
576
|
+
if (!predicate(as[i])) {
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return i;
|
|
581
|
+
};
|
|
582
|
+
function spanLeft(predicate) {
|
|
583
|
+
return function (as) {
|
|
584
|
+
var _a = (0, exports.splitAt)(spanLeftIndex(as, predicate))(as), init = _a[0], rest = _a[1];
|
|
585
|
+
return { init: init, rest: rest };
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
exports.spanLeft = spanLeft;
|
|
589
|
+
/**
|
|
590
|
+
* Drop a max number of elements from the start of an `ReadonlyArray`, creating a new `ReadonlyArray`.
|
|
591
|
+
*
|
|
592
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* import * as RA from 'fp-ts/ReadonlyArray'
|
|
596
|
+
* import { pipe } from 'fp-ts/function'
|
|
597
|
+
*
|
|
598
|
+
* const input: ReadonlyArray<number> = [1, 2, 3]
|
|
599
|
+
* assert.deepStrictEqual(pipe(input, RA.dropLeft(2)), [3])
|
|
600
|
+
* assert.strictEqual(pipe(input, RA.dropLeft(0)), input)
|
|
601
|
+
* assert.strictEqual(pipe(input, RA.dropLeft(-1)), input)
|
|
602
|
+
*
|
|
603
|
+
* @category combinators
|
|
604
|
+
* @since 2.5.0
|
|
605
|
+
*/
|
|
606
|
+
var dropLeft = function (n) { return function (as) {
|
|
607
|
+
return n <= 0 || (0, exports.isEmpty)(as) ? as : n >= as.length ? exports.empty : as.slice(n, as.length);
|
|
608
|
+
}; };
|
|
609
|
+
exports.dropLeft = dropLeft;
|
|
610
|
+
/**
|
|
611
|
+
* Drop a max number of elements from the end of an `ReadonlyArray`, creating a new `ReadonlyArray`.
|
|
612
|
+
*
|
|
613
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* import * as RA from 'fp-ts/ReadonlyArray'
|
|
617
|
+
* import { pipe } from 'fp-ts/function'
|
|
618
|
+
*
|
|
619
|
+
* const input: ReadonlyArray<number> = [1, 2, 3]
|
|
620
|
+
* assert.deepStrictEqual(pipe(input, RA.dropRight(2)), [1])
|
|
621
|
+
* assert.strictEqual(pipe(input, RA.dropRight(0)), input)
|
|
622
|
+
* assert.strictEqual(pipe(input, RA.dropRight(-1)), input)
|
|
623
|
+
*
|
|
624
|
+
* @category combinators
|
|
625
|
+
* @since 2.5.0
|
|
626
|
+
*/
|
|
627
|
+
var dropRight = function (n) { return function (as) {
|
|
628
|
+
return n <= 0 || (0, exports.isEmpty)(as) ? as : n >= as.length ? exports.empty : as.slice(0, as.length - n);
|
|
629
|
+
}; };
|
|
630
|
+
exports.dropRight = dropRight;
|
|
631
|
+
function dropLeftWhile(predicate) {
|
|
632
|
+
return function (as) {
|
|
633
|
+
var i = spanLeftIndex(as, predicate);
|
|
634
|
+
return i === 0 ? as : i === as.length ? exports.empty : as.slice(i);
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
exports.dropLeftWhile = dropLeftWhile;
|
|
638
|
+
/**
|
|
639
|
+
* Find the first index for which a predicate holds
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* import { findIndex } from 'fp-ts/ReadonlyArray'
|
|
643
|
+
* import { some, none } from 'fp-ts/Option'
|
|
644
|
+
*
|
|
645
|
+
* assert.deepStrictEqual(findIndex((n: number) => n === 2)([1, 2, 3]), some(1))
|
|
646
|
+
* assert.deepStrictEqual(findIndex((n: number) => n === 2)([]), none)
|
|
647
|
+
*
|
|
648
|
+
* @since 2.5.0
|
|
649
|
+
*/
|
|
650
|
+
var findIndex = function (predicate) { return function (as) {
|
|
651
|
+
for (var i = 0; i < as.length; i++) {
|
|
652
|
+
if (predicate(as[i])) {
|
|
653
|
+
return _.some(i);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return _.none;
|
|
657
|
+
}; };
|
|
658
|
+
exports.findIndex = findIndex;
|
|
659
|
+
function findFirst(predicate) {
|
|
660
|
+
return function (as) {
|
|
661
|
+
for (var i = 0; i < as.length; i++) {
|
|
662
|
+
if (predicate(as[i])) {
|
|
663
|
+
return _.some(as[i]);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return _.none;
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
exports.findFirst = findFirst;
|
|
670
|
+
/**
|
|
671
|
+
* Find the first element returned by an option based selector function
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* import { findFirstMap } from 'fp-ts/ReadonlyArray'
|
|
675
|
+
* import { some, none } from 'fp-ts/Option'
|
|
676
|
+
*
|
|
677
|
+
* interface Person {
|
|
678
|
+
* readonly name: string
|
|
679
|
+
* readonly age?: number
|
|
680
|
+
* }
|
|
681
|
+
*
|
|
682
|
+
* const persons: ReadonlyArray<Person> = [{ name: 'John' }, { name: 'Mary', age: 45 }, { name: 'Joey', age: 28 }]
|
|
683
|
+
*
|
|
684
|
+
* // returns the name of the first person that has an age
|
|
685
|
+
* assert.deepStrictEqual(findFirstMap((p: Person) => (p.age === undefined ? none : some(p.name)))(persons), some('Mary'))
|
|
686
|
+
*
|
|
687
|
+
* @since 2.5.0
|
|
688
|
+
*/
|
|
689
|
+
var findFirstMap = function (f) { return function (as) {
|
|
690
|
+
for (var i = 0; i < as.length; i++) {
|
|
691
|
+
var out = f(as[i]);
|
|
692
|
+
if (_.isSome(out)) {
|
|
693
|
+
return out;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return _.none;
|
|
697
|
+
}; };
|
|
698
|
+
exports.findFirstMap = findFirstMap;
|
|
699
|
+
function findLast(predicate) {
|
|
700
|
+
return function (as) {
|
|
701
|
+
for (var i = as.length - 1; i >= 0; i--) {
|
|
702
|
+
if (predicate(as[i])) {
|
|
703
|
+
return _.some(as[i]);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return _.none;
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
exports.findLast = findLast;
|
|
710
|
+
/**
|
|
711
|
+
* Find the last element returned by an option based selector function
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* import { findLastMap } from 'fp-ts/ReadonlyArray'
|
|
715
|
+
* import { some, none } from 'fp-ts/Option'
|
|
716
|
+
*
|
|
717
|
+
* interface Person {
|
|
718
|
+
* readonly name: string
|
|
719
|
+
* readonly age?: number
|
|
720
|
+
* }
|
|
721
|
+
*
|
|
722
|
+
* const persons: ReadonlyArray<Person> = [{ name: 'John' }, { name: 'Mary', age: 45 }, { name: 'Joey', age: 28 }]
|
|
723
|
+
*
|
|
724
|
+
* // returns the name of the last person that has an age
|
|
725
|
+
* assert.deepStrictEqual(findLastMap((p: Person) => (p.age === undefined ? none : some(p.name)))(persons), some('Joey'))
|
|
726
|
+
*
|
|
727
|
+
* @since 2.5.0
|
|
728
|
+
*/
|
|
729
|
+
var findLastMap = function (f) { return function (as) {
|
|
730
|
+
for (var i = as.length - 1; i >= 0; i--) {
|
|
731
|
+
var out = f(as[i]);
|
|
732
|
+
if (_.isSome(out)) {
|
|
733
|
+
return out;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return _.none;
|
|
737
|
+
}; };
|
|
738
|
+
exports.findLastMap = findLastMap;
|
|
739
|
+
/**
|
|
740
|
+
* Returns the index of the last element of the list which matches the predicate
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* import { findLastIndex } from 'fp-ts/ReadonlyArray'
|
|
744
|
+
* import { some, none } from 'fp-ts/Option'
|
|
745
|
+
*
|
|
746
|
+
* interface X {
|
|
747
|
+
* readonly a: number
|
|
748
|
+
* readonly b: number
|
|
749
|
+
* }
|
|
750
|
+
* const xs: ReadonlyArray<X> = [{ a: 1, b: 0 }, { a: 1, b: 1 }]
|
|
751
|
+
* assert.deepStrictEqual(findLastIndex((x: { readonly a: number }) => x.a === 1)(xs), some(1))
|
|
752
|
+
* assert.deepStrictEqual(findLastIndex((x: { readonly a: number }) => x.a === 4)(xs), none)
|
|
753
|
+
*
|
|
754
|
+
*
|
|
755
|
+
* @since 2.5.0
|
|
756
|
+
*/
|
|
757
|
+
var findLastIndex = function (predicate) { return function (as) {
|
|
758
|
+
for (var i = as.length - 1; i >= 0; i--) {
|
|
759
|
+
if (predicate(as[i])) {
|
|
760
|
+
return _.some(i);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return _.none;
|
|
764
|
+
}; };
|
|
765
|
+
exports.findLastIndex = findLastIndex;
|
|
766
|
+
/**
|
|
767
|
+
* Insert an element at the specified index, creating a new array, or returning `None` if the index is out of bounds
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* import { insertAt } from 'fp-ts/ReadonlyArray'
|
|
771
|
+
* import { some } from 'fp-ts/Option'
|
|
772
|
+
*
|
|
773
|
+
* assert.deepStrictEqual(insertAt(2, 5)([1, 2, 3, 4]), some([1, 2, 5, 3, 4]))
|
|
774
|
+
*
|
|
775
|
+
* @since 2.5.0
|
|
776
|
+
*/
|
|
777
|
+
var insertAt = function (i, a) { return function (as) {
|
|
778
|
+
return i < 0 || i > as.length ? _.none : _.some(RNEA.unsafeInsertAt(i, a, as));
|
|
779
|
+
}; };
|
|
780
|
+
exports.insertAt = insertAt;
|
|
781
|
+
/**
|
|
782
|
+
* Change the element at the specified index, creating a new array, or returning `None` if the index is out of bounds
|
|
783
|
+
*
|
|
784
|
+
* @example
|
|
785
|
+
* import { updateAt } from 'fp-ts/ReadonlyArray'
|
|
786
|
+
* import { some, none } from 'fp-ts/Option'
|
|
787
|
+
*
|
|
788
|
+
* assert.deepStrictEqual(updateAt(1, 1)([1, 2, 3]), some([1, 1, 3]))
|
|
789
|
+
* assert.deepStrictEqual(updateAt(1, 1)([]), none)
|
|
790
|
+
*
|
|
791
|
+
* @since 2.5.0
|
|
792
|
+
*/
|
|
793
|
+
var updateAt = function (i, a) {
|
|
794
|
+
return (0, exports.modifyAt)(i, function () { return a; });
|
|
795
|
+
};
|
|
796
|
+
exports.updateAt = updateAt;
|
|
797
|
+
/**
|
|
798
|
+
* Delete the element at the specified index, creating a new array, or returning `None` if the index is out of bounds
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* import { deleteAt } from 'fp-ts/ReadonlyArray'
|
|
802
|
+
* import { some, none } from 'fp-ts/Option'
|
|
803
|
+
*
|
|
804
|
+
* assert.deepStrictEqual(deleteAt(0)([1, 2, 3]), some([2, 3]))
|
|
805
|
+
* assert.deepStrictEqual(deleteAt(1)([]), none)
|
|
806
|
+
*
|
|
807
|
+
* @since 2.5.0
|
|
808
|
+
*/
|
|
809
|
+
var deleteAt = function (i) { return function (as) {
|
|
810
|
+
return (0, exports.isOutOfBound)(i, as) ? _.none : _.some((0, exports.unsafeDeleteAt)(i, as));
|
|
811
|
+
}; };
|
|
812
|
+
exports.deleteAt = deleteAt;
|
|
813
|
+
/**
|
|
814
|
+
* Apply a function to the element at the specified index, creating a new array, or returning `None` if the index is out
|
|
815
|
+
* of bounds
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* import { modifyAt } from 'fp-ts/ReadonlyArray'
|
|
819
|
+
* import { some, none } from 'fp-ts/Option'
|
|
820
|
+
*
|
|
821
|
+
* const double = (x: number): number => x * 2
|
|
822
|
+
* assert.deepStrictEqual(modifyAt(1, double)([1, 2, 3]), some([1, 4, 3]))
|
|
823
|
+
* assert.deepStrictEqual(modifyAt(1, double)([]), none)
|
|
824
|
+
*
|
|
825
|
+
* @since 2.5.0
|
|
826
|
+
*/
|
|
827
|
+
var modifyAt = function (i, f) { return function (as) {
|
|
828
|
+
return (0, exports.isOutOfBound)(i, as) ? _.none : _.some((0, exports.unsafeUpdateAt)(i, f(as[i]), as));
|
|
829
|
+
}; };
|
|
830
|
+
exports.modifyAt = modifyAt;
|
|
831
|
+
/**
|
|
832
|
+
* Reverse an array, creating a new array
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* import { reverse } from 'fp-ts/ReadonlyArray'
|
|
836
|
+
*
|
|
837
|
+
* assert.deepStrictEqual(reverse([1, 2, 3]), [3, 2, 1])
|
|
838
|
+
*
|
|
839
|
+
* @category combinators
|
|
840
|
+
* @since 2.5.0
|
|
841
|
+
*/
|
|
842
|
+
var reverse = function (as) { return (as.length <= 1 ? as : as.slice().reverse()); };
|
|
843
|
+
exports.reverse = reverse;
|
|
844
|
+
/**
|
|
845
|
+
* Extracts from an array of `Either` all the `Right` elements. All the `Right` elements are extracted in order
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* import { rights } from 'fp-ts/ReadonlyArray'
|
|
849
|
+
* import { right, left } from 'fp-ts/Either'
|
|
850
|
+
*
|
|
851
|
+
* assert.deepStrictEqual(rights([right(1), left('foo'), right(2)]), [1, 2])
|
|
852
|
+
*
|
|
853
|
+
* @category combinators
|
|
854
|
+
* @since 2.5.0
|
|
855
|
+
*/
|
|
856
|
+
var rights = function (as) {
|
|
857
|
+
var r = [];
|
|
858
|
+
for (var i = 0; i < as.length; i++) {
|
|
859
|
+
var a = as[i];
|
|
860
|
+
if (a._tag === 'Right') {
|
|
861
|
+
r.push(a.right);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return r;
|
|
865
|
+
};
|
|
866
|
+
exports.rights = rights;
|
|
867
|
+
/**
|
|
868
|
+
* Extracts from an array of `Either` all the `Left` elements. All the `Left` elements are extracted in order
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* import { lefts } from 'fp-ts/ReadonlyArray'
|
|
872
|
+
* import { left, right } from 'fp-ts/Either'
|
|
873
|
+
*
|
|
874
|
+
* assert.deepStrictEqual(lefts([right(1), left('foo'), right(2)]), ['foo'])
|
|
875
|
+
*
|
|
876
|
+
* @category combinators
|
|
877
|
+
* @since 2.5.0
|
|
878
|
+
*/
|
|
879
|
+
var lefts = function (as) {
|
|
880
|
+
var r = [];
|
|
881
|
+
for (var i = 0; i < as.length; i++) {
|
|
882
|
+
var a = as[i];
|
|
883
|
+
if (a._tag === 'Left') {
|
|
884
|
+
r.push(a.left);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return r;
|
|
888
|
+
};
|
|
889
|
+
exports.lefts = lefts;
|
|
890
|
+
/**
|
|
891
|
+
* Sort the elements of an array in increasing order, creating a new array
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* import { sort } from 'fp-ts/ReadonlyArray'
|
|
895
|
+
* import * as N from 'fp-ts/number'
|
|
896
|
+
*
|
|
897
|
+
* assert.deepStrictEqual(sort(N.Ord)([3, 2, 1]), [1, 2, 3])
|
|
898
|
+
*
|
|
899
|
+
* @category combinators
|
|
900
|
+
* @since 2.5.0
|
|
901
|
+
*/
|
|
902
|
+
var sort = function (O) { return function (as) {
|
|
903
|
+
return as.length <= 1 ? as : as.slice().sort(O.compare);
|
|
904
|
+
}; };
|
|
905
|
+
exports.sort = sort;
|
|
906
|
+
// TODO: curry and make data-last in v3
|
|
907
|
+
/**
|
|
908
|
+
* Apply a function to pairs of elements at the same index in two arrays, collecting the results in a new array. If one
|
|
909
|
+
* input array is short, excess elements of the longer array are discarded.
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* import { zipWith } from 'fp-ts/ReadonlyArray'
|
|
913
|
+
*
|
|
914
|
+
* assert.deepStrictEqual(zipWith([1, 2, 3], ['a', 'b', 'c', 'd'], (n, s) => s + n), ['a1', 'b2', 'c3'])
|
|
915
|
+
*
|
|
916
|
+
* @category combinators
|
|
917
|
+
* @since 2.5.0
|
|
918
|
+
*/
|
|
919
|
+
var zipWith = function (fa, fb, f) {
|
|
920
|
+
var fc = [];
|
|
921
|
+
var len = Math.min(fa.length, fb.length);
|
|
922
|
+
for (var i = 0; i < len; i++) {
|
|
923
|
+
fc[i] = f(fa[i], fb[i]);
|
|
924
|
+
}
|
|
925
|
+
return fc;
|
|
926
|
+
};
|
|
927
|
+
exports.zipWith = zipWith;
|
|
928
|
+
function zip(as, bs) {
|
|
929
|
+
if (bs === undefined) {
|
|
930
|
+
return function (bs) { return zip(bs, as); };
|
|
931
|
+
}
|
|
932
|
+
return (0, exports.zipWith)(as, bs, function (a, b) { return [a, b]; });
|
|
933
|
+
}
|
|
934
|
+
exports.zip = zip;
|
|
935
|
+
/**
|
|
936
|
+
* The function is reverse of `zip`. Takes an array of pairs and return two corresponding arrays
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* import { unzip } from 'fp-ts/ReadonlyArray'
|
|
940
|
+
*
|
|
941
|
+
* assert.deepStrictEqual(unzip([[1, 'a'], [2, 'b'], [3, 'c']]), [[1, 2, 3], ['a', 'b', 'c']])
|
|
942
|
+
*
|
|
943
|
+
* @category combinators
|
|
944
|
+
* @since 2.5.0
|
|
945
|
+
*/
|
|
946
|
+
var unzip = function (as) {
|
|
947
|
+
var fa = [];
|
|
948
|
+
var fb = [];
|
|
949
|
+
for (var i = 0; i < as.length; i++) {
|
|
950
|
+
fa[i] = as[i][0];
|
|
951
|
+
fb[i] = as[i][1];
|
|
952
|
+
}
|
|
953
|
+
return [fa, fb];
|
|
954
|
+
};
|
|
955
|
+
exports.unzip = unzip;
|
|
956
|
+
/**
|
|
957
|
+
* Prepend an element to every member of an array
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* import { prependAll } from 'fp-ts/ReadonlyArray'
|
|
961
|
+
*
|
|
962
|
+
* assert.deepStrictEqual(prependAll(9)([1, 2, 3, 4]), [9, 1, 9, 2, 9, 3, 9, 4])
|
|
963
|
+
*
|
|
964
|
+
* @category combinators
|
|
965
|
+
* @since 2.10.0
|
|
966
|
+
*/
|
|
967
|
+
var prependAll = function (middle) {
|
|
968
|
+
var f = RNEA.prependAll(middle);
|
|
969
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : as); };
|
|
970
|
+
};
|
|
971
|
+
exports.prependAll = prependAll;
|
|
972
|
+
/**
|
|
973
|
+
* Places an element in between members of an array
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* import { intersperse } from 'fp-ts/ReadonlyArray'
|
|
977
|
+
*
|
|
978
|
+
* assert.deepStrictEqual(intersperse(9)([1, 2, 3, 4]), [1, 9, 2, 9, 3, 9, 4])
|
|
979
|
+
*
|
|
980
|
+
* @category combinators
|
|
981
|
+
* @since 2.9.0
|
|
982
|
+
*/
|
|
983
|
+
var intersperse = function (middle) {
|
|
984
|
+
var f = RNEA.intersperse(middle);
|
|
985
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : as); };
|
|
986
|
+
};
|
|
987
|
+
exports.intersperse = intersperse;
|
|
988
|
+
/**
|
|
989
|
+
* Rotate a `ReadonlyArray` by `n` steps.
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* import { rotate } from 'fp-ts/ReadonlyArray'
|
|
993
|
+
*
|
|
994
|
+
* assert.deepStrictEqual(rotate(2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3])
|
|
995
|
+
*
|
|
996
|
+
* @category combinators
|
|
997
|
+
* @since 2.5.0
|
|
998
|
+
*/
|
|
999
|
+
var rotate = function (n) {
|
|
1000
|
+
var f = RNEA.rotate(n);
|
|
1001
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : as); };
|
|
1002
|
+
};
|
|
1003
|
+
exports.rotate = rotate;
|
|
1004
|
+
function elem(E) {
|
|
1005
|
+
return function (a, as) {
|
|
1006
|
+
if (as === undefined) {
|
|
1007
|
+
var elemE_1 = elem(E);
|
|
1008
|
+
return function (as) { return elemE_1(a, as); };
|
|
1009
|
+
}
|
|
1010
|
+
var predicate = function (element) { return E.equals(element, a); };
|
|
1011
|
+
var i = 0;
|
|
1012
|
+
for (; i < as.length; i++) {
|
|
1013
|
+
if (predicate(as[i])) {
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return false;
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
exports.elem = elem;
|
|
1021
|
+
/**
|
|
1022
|
+
* Remove duplicates from an array, keeping the first occurrence of an element.
|
|
1023
|
+
*
|
|
1024
|
+
* @example
|
|
1025
|
+
* import { uniq } from 'fp-ts/ReadonlyArray'
|
|
1026
|
+
* import * as N from 'fp-ts/number'
|
|
1027
|
+
*
|
|
1028
|
+
* assert.deepStrictEqual(uniq(N.Eq)([1, 2, 1]), [1, 2])
|
|
1029
|
+
*
|
|
1030
|
+
* @category combinators
|
|
1031
|
+
* @since 2.5.0
|
|
1032
|
+
*/
|
|
1033
|
+
var uniq = function (E) {
|
|
1034
|
+
var f = RNEA.uniq(E);
|
|
1035
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : as); };
|
|
1036
|
+
};
|
|
1037
|
+
exports.uniq = uniq;
|
|
1038
|
+
/**
|
|
1039
|
+
* Sort the elements of an array in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`,
|
|
1040
|
+
* etc...
|
|
1041
|
+
*
|
|
1042
|
+
* @example
|
|
1043
|
+
* import { sortBy } from 'fp-ts/ReadonlyArray'
|
|
1044
|
+
* import { contramap } from 'fp-ts/Ord'
|
|
1045
|
+
* import * as S from 'fp-ts/string'
|
|
1046
|
+
* import * as N from 'fp-ts/number'
|
|
1047
|
+
* import { pipe } from 'fp-ts/function'
|
|
1048
|
+
*
|
|
1049
|
+
* interface Person {
|
|
1050
|
+
* readonly name: string
|
|
1051
|
+
* readonly age: number
|
|
1052
|
+
* }
|
|
1053
|
+
* const byName = pipe(S.Ord, contramap((p: Person) => p.name))
|
|
1054
|
+
* const byAge = pipe(N.Ord, contramap((p: Person) => p.age))
|
|
1055
|
+
*
|
|
1056
|
+
* const sortByNameByAge = sortBy([byName, byAge])
|
|
1057
|
+
*
|
|
1058
|
+
* const persons = [{ name: 'a', age: 1 }, { name: 'b', age: 3 }, { name: 'c', age: 2 }, { name: 'b', age: 2 }]
|
|
1059
|
+
* assert.deepStrictEqual(sortByNameByAge(persons), [
|
|
1060
|
+
* { name: 'a', age: 1 },
|
|
1061
|
+
* { name: 'b', age: 2 },
|
|
1062
|
+
* { name: 'b', age: 3 },
|
|
1063
|
+
* { name: 'c', age: 2 }
|
|
1064
|
+
* ])
|
|
1065
|
+
*
|
|
1066
|
+
* @category combinators
|
|
1067
|
+
* @since 2.5.0
|
|
1068
|
+
*/
|
|
1069
|
+
var sortBy = function (ords) {
|
|
1070
|
+
var f = RNEA.sortBy(ords);
|
|
1071
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : as); };
|
|
1072
|
+
};
|
|
1073
|
+
exports.sortBy = sortBy;
|
|
1074
|
+
/**
|
|
1075
|
+
* A useful recursion pattern for processing a `ReadonlyArray` to produce a new `ReadonlyArray`, often used for "chopping" up the input
|
|
1076
|
+
* `ReadonlyArray`. Typically `chop` is called with some function that will consume an initial prefix of the `ReadonlyArray` and produce a
|
|
1077
|
+
* value and the tail of the `ReadonlyArray`.
|
|
1078
|
+
*
|
|
1079
|
+
* @example
|
|
1080
|
+
* import { Eq } from 'fp-ts/Eq'
|
|
1081
|
+
* import * as RA from 'fp-ts/ReadonlyArray'
|
|
1082
|
+
* import * as N from 'fp-ts/number'
|
|
1083
|
+
* import { pipe } from 'fp-ts/function'
|
|
1084
|
+
*
|
|
1085
|
+
* const group = <A>(S: Eq<A>): ((as: ReadonlyArray<A>) => ReadonlyArray<ReadonlyArray<A>>) => {
|
|
1086
|
+
* return RA.chop(as => {
|
|
1087
|
+
* const { init, rest } = pipe(as, RA.spanLeft((a: A) => S.equals(a, as[0])))
|
|
1088
|
+
* return [init, rest]
|
|
1089
|
+
* })
|
|
1090
|
+
* }
|
|
1091
|
+
* assert.deepStrictEqual(group(N.Eq)([1, 1, 2, 3, 3, 4]), [[1, 1], [2], [3, 3], [4]])
|
|
1092
|
+
*
|
|
1093
|
+
* @category combinators
|
|
1094
|
+
* @since 2.5.0
|
|
1095
|
+
*/
|
|
1096
|
+
var chop = function (f) {
|
|
1097
|
+
var g = RNEA.chop(f);
|
|
1098
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? g(as) : exports.empty); };
|
|
1099
|
+
};
|
|
1100
|
+
exports.chop = chop;
|
|
1101
|
+
/**
|
|
1102
|
+
* Splits a `ReadonlyArray` into two pieces, the first piece has max `n` elements.
|
|
1103
|
+
*
|
|
1104
|
+
* @example
|
|
1105
|
+
* import { splitAt } from 'fp-ts/ReadonlyArray'
|
|
1106
|
+
*
|
|
1107
|
+
* assert.deepStrictEqual(splitAt(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4, 5]])
|
|
1108
|
+
*
|
|
1109
|
+
* @category combinators
|
|
1110
|
+
* @since 2.5.0
|
|
1111
|
+
*/
|
|
1112
|
+
var splitAt = function (n) { return function (as) {
|
|
1113
|
+
return n >= 1 && (0, exports.isNonEmpty)(as) ? RNEA.splitAt(n)(as) : (0, exports.isEmpty)(as) ? [as, exports.empty] : [exports.empty, as];
|
|
1114
|
+
}; };
|
|
1115
|
+
exports.splitAt = splitAt;
|
|
1116
|
+
/**
|
|
1117
|
+
* Splits a `ReadonlyArray` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
1118
|
+
* the `ReadonlyArray`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
1119
|
+
* definition of `chunksOf`; it satisfies the property that:
|
|
1120
|
+
*
|
|
1121
|
+
* ```ts
|
|
1122
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
1123
|
+
* ```
|
|
1124
|
+
*
|
|
1125
|
+
* whenever `n` evenly divides the length of `as`.
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* import { chunksOf } from 'fp-ts/ReadonlyArray'
|
|
1129
|
+
*
|
|
1130
|
+
* assert.deepStrictEqual(chunksOf(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4], [5]])
|
|
1131
|
+
*
|
|
1132
|
+
* @category combinators
|
|
1133
|
+
* @since 2.5.0
|
|
1134
|
+
*/
|
|
1135
|
+
var chunksOf = function (n) {
|
|
1136
|
+
var f = RNEA.chunksOf(n);
|
|
1137
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : exports.empty); };
|
|
1138
|
+
};
|
|
1139
|
+
exports.chunksOf = chunksOf;
|
|
1140
|
+
/**
|
|
1141
|
+
* @category combinators
|
|
1142
|
+
* @since 2.11.0
|
|
1143
|
+
*/
|
|
1144
|
+
var fromOptionK = function (f) { return function () {
|
|
1145
|
+
var a = [];
|
|
1146
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1147
|
+
a[_i] = arguments[_i];
|
|
1148
|
+
}
|
|
1149
|
+
return (0, exports.fromOption)(f.apply(void 0, a));
|
|
1150
|
+
}; };
|
|
1151
|
+
exports.fromOptionK = fromOptionK;
|
|
1152
|
+
function comprehension(input, f, g) {
|
|
1153
|
+
if (g === void 0) { g = function () { return true; }; }
|
|
1154
|
+
var go = function (scope, input) {
|
|
1155
|
+
return (0, exports.isNonEmpty)(input)
|
|
1156
|
+
? (0, _function.pipe)(RNEA.head(input), (0, exports.chain)(function (x) { return go((0, _function.pipe)(scope, (0, exports.append)(x)), RNEA.tail(input)); }))
|
|
1157
|
+
: g.apply(void 0, scope) ? [f.apply(void 0, scope)]
|
|
1158
|
+
: exports.empty;
|
|
1159
|
+
};
|
|
1160
|
+
return go(exports.empty, input);
|
|
1161
|
+
}
|
|
1162
|
+
exports.comprehension = comprehension;
|
|
1163
|
+
/**
|
|
1164
|
+
* @category combinators
|
|
1165
|
+
* @since 2.11.0
|
|
1166
|
+
*/
|
|
1167
|
+
var concatW = function (second) { return function (first) {
|
|
1168
|
+
return (0, exports.isEmpty)(first) ? second : (0, exports.isEmpty)(second) ? first : first.concat(second);
|
|
1169
|
+
}; };
|
|
1170
|
+
exports.concatW = concatW;
|
|
1171
|
+
/**
|
|
1172
|
+
* @category combinators
|
|
1173
|
+
* @since 2.11.0
|
|
1174
|
+
*/
|
|
1175
|
+
exports.concat = exports.concatW;
|
|
1176
|
+
function union(E) {
|
|
1177
|
+
var unionE = RNEA.union(E);
|
|
1178
|
+
return function (first, second) {
|
|
1179
|
+
if (second === undefined) {
|
|
1180
|
+
var unionE_1 = union(E);
|
|
1181
|
+
return function (second) { return unionE_1(second, first); };
|
|
1182
|
+
}
|
|
1183
|
+
return (0, exports.isNonEmpty)(first) && (0, exports.isNonEmpty)(second) ? unionE(second)(first) : (0, exports.isNonEmpty)(first) ? first : second;
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
exports.union = union;
|
|
1187
|
+
function intersection(E) {
|
|
1188
|
+
var elemE = elem(E);
|
|
1189
|
+
return function (xs, ys) {
|
|
1190
|
+
if (ys === undefined) {
|
|
1191
|
+
var intersectionE_1 = intersection(E);
|
|
1192
|
+
return function (ys) { return intersectionE_1(ys, xs); };
|
|
1193
|
+
}
|
|
1194
|
+
return xs.filter(function (a) { return elemE(a, ys); });
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
exports.intersection = intersection;
|
|
1198
|
+
function difference(E) {
|
|
1199
|
+
var elemE = elem(E);
|
|
1200
|
+
return function (xs, ys) {
|
|
1201
|
+
if (ys === undefined) {
|
|
1202
|
+
var differenceE_1 = difference(E);
|
|
1203
|
+
return function (ys) { return differenceE_1(ys, xs); };
|
|
1204
|
+
}
|
|
1205
|
+
return xs.filter(function (a) { return !elemE(a, ys); });
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
exports.difference = difference;
|
|
1209
|
+
// -------------------------------------------------------------------------------------
|
|
1210
|
+
// non-pipeables
|
|
1211
|
+
// -------------------------------------------------------------------------------------
|
|
1212
|
+
var _map = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.map)(f)); };
|
|
1213
|
+
var _mapWithIndex = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.mapWithIndex)(f)); };
|
|
1214
|
+
var _ap = function (fab, fa) { return (0, _function.pipe)(fab, (0, exports.ap)(fa)); };
|
|
1215
|
+
var _chain = function (ma, f) { return (0, _function.pipe)(ma, (0, exports.chain)(f)); };
|
|
1216
|
+
var _filter = function (fa, predicate) {
|
|
1217
|
+
return (0, _function.pipe)(fa, (0, exports.filter)(predicate));
|
|
1218
|
+
};
|
|
1219
|
+
var _filterMap = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.filterMap)(f)); };
|
|
1220
|
+
var _partition = function (fa, predicate) {
|
|
1221
|
+
return (0, _function.pipe)(fa, (0, exports.partition)(predicate));
|
|
1222
|
+
};
|
|
1223
|
+
var _partitionMap = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.partitionMap)(f)); };
|
|
1224
|
+
var _partitionWithIndex = function (fa, predicateWithIndex) { return (0, _function.pipe)(fa, (0, exports.partitionWithIndex)(predicateWithIndex)); };
|
|
1225
|
+
var _partitionMapWithIndex = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.partitionMapWithIndex)(f)); };
|
|
1226
|
+
var _alt = function (fa, that) { return (0, _function.pipe)(fa, (0, exports.alt)(that)); };
|
|
1227
|
+
var _reduce = function (fa, b, f) { return (0, _function.pipe)(fa, (0, exports.reduce)(b, f)); };
|
|
1228
|
+
var _foldMap = function (M) {
|
|
1229
|
+
var foldMapM = (0, exports.foldMap)(M);
|
|
1230
|
+
return function (fa, f) { return (0, _function.pipe)(fa, foldMapM(f)); };
|
|
1231
|
+
};
|
|
1232
|
+
var _reduceRight = function (fa, b, f) { return (0, _function.pipe)(fa, (0, exports.reduceRight)(b, f)); };
|
|
1233
|
+
var _reduceWithIndex = function (fa, b, f) {
|
|
1234
|
+
return (0, _function.pipe)(fa, (0, exports.reduceWithIndex)(b, f));
|
|
1235
|
+
};
|
|
1236
|
+
var _foldMapWithIndex = function (M) {
|
|
1237
|
+
var foldMapWithIndexM = (0, exports.foldMapWithIndex)(M);
|
|
1238
|
+
return function (fa, f) { return (0, _function.pipe)(fa, foldMapWithIndexM(f)); };
|
|
1239
|
+
};
|
|
1240
|
+
var _reduceRightWithIndex = function (fa, b, f) {
|
|
1241
|
+
return (0, _function.pipe)(fa, (0, exports.reduceRightWithIndex)(b, f));
|
|
1242
|
+
};
|
|
1243
|
+
var _filterMapWithIndex = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.filterMapWithIndex)(f)); };
|
|
1244
|
+
var _filterWithIndex = function (fa, predicateWithIndex) { return (0, _function.pipe)(fa, (0, exports.filterWithIndex)(predicateWithIndex)); };
|
|
1245
|
+
var _extend = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.extend)(f)); };
|
|
1246
|
+
var _traverse = function (F) {
|
|
1247
|
+
var traverseF = (0, exports.traverse)(F);
|
|
1248
|
+
return function (ta, f) { return (0, _function.pipe)(ta, traverseF(f)); };
|
|
1249
|
+
};
|
|
1250
|
+
/* istanbul ignore next */
|
|
1251
|
+
var _traverseWithIndex = function (F) {
|
|
1252
|
+
var traverseWithIndexF = (0, exports.traverseWithIndex)(F);
|
|
1253
|
+
return function (ta, f) { return (0, _function.pipe)(ta, traverseWithIndexF(f)); };
|
|
1254
|
+
};
|
|
1255
|
+
/** @internal */
|
|
1256
|
+
var _chainRecDepthFirst = function (a, f) { return (0, _function.pipe)(a, (0, exports.chainRecDepthFirst)(f)); };
|
|
1257
|
+
exports._chainRecDepthFirst = _chainRecDepthFirst;
|
|
1258
|
+
/** @internal */
|
|
1259
|
+
var _chainRecBreadthFirst = function (a, f) { return (0, _function.pipe)(a, (0, exports.chainRecBreadthFirst)(f)); };
|
|
1260
|
+
exports._chainRecBreadthFirst = _chainRecBreadthFirst;
|
|
1261
|
+
// -------------------------------------------------------------------------------------
|
|
1262
|
+
// type class members
|
|
1263
|
+
// -------------------------------------------------------------------------------------
|
|
1264
|
+
/**
|
|
1265
|
+
* @category Pointed
|
|
1266
|
+
* @since 2.5.0
|
|
1267
|
+
*/
|
|
1268
|
+
exports.of = RNEA.of;
|
|
1269
|
+
/**
|
|
1270
|
+
* @category Zero
|
|
1271
|
+
* @since 2.7.0
|
|
1272
|
+
*/
|
|
1273
|
+
var zero = function () { return exports.empty; };
|
|
1274
|
+
exports.zero = zero;
|
|
1275
|
+
/**
|
|
1276
|
+
* Less strict version of [`alt`](#alt).
|
|
1277
|
+
*
|
|
1278
|
+
* @category Alt
|
|
1279
|
+
* @since 2.9.0
|
|
1280
|
+
*/
|
|
1281
|
+
var altW = function (that) { return function (fa) {
|
|
1282
|
+
return fa.concat(that());
|
|
1283
|
+
}; };
|
|
1284
|
+
exports.altW = altW;
|
|
1285
|
+
/**
|
|
1286
|
+
* Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
|
|
1287
|
+
* types of kind `* -> *`.
|
|
1288
|
+
*
|
|
1289
|
+
* @category Alt
|
|
1290
|
+
* @since 2.5.0
|
|
1291
|
+
*/
|
|
1292
|
+
exports.alt = exports.altW;
|
|
1293
|
+
/**
|
|
1294
|
+
* Apply a function to an argument under a type constructor.
|
|
1295
|
+
*
|
|
1296
|
+
* @category Apply
|
|
1297
|
+
* @since 2.5.0
|
|
1298
|
+
*/
|
|
1299
|
+
var ap = function (fa) {
|
|
1300
|
+
return (0, exports.chain)(function (f) { return (0, _function.pipe)(fa, (0, exports.map)(f)); });
|
|
1301
|
+
};
|
|
1302
|
+
exports.ap = ap;
|
|
1303
|
+
/**
|
|
1304
|
+
* Composes computations in sequence, using the return value of one computation to determine the next computation.
|
|
1305
|
+
*
|
|
1306
|
+
* @category Monad
|
|
1307
|
+
* @since 2.5.0
|
|
1308
|
+
*/
|
|
1309
|
+
var chain = function (f) { return function (ma) {
|
|
1310
|
+
return (0, _function.pipe)(ma, (0, exports.chainWithIndex)(function (_, a) { return f(a); }));
|
|
1311
|
+
}; };
|
|
1312
|
+
exports.chain = chain;
|
|
1313
|
+
/**
|
|
1314
|
+
* Derivable from `Chain`.
|
|
1315
|
+
*
|
|
1316
|
+
* @category combinators
|
|
1317
|
+
* @since 2.5.0
|
|
1318
|
+
*/
|
|
1319
|
+
exports.flatten = (0, exports.chain)(_function.identity);
|
|
1320
|
+
/**
|
|
1321
|
+
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
|
|
1322
|
+
* use the type constructor `F` to represent some computational context.
|
|
1323
|
+
*
|
|
1324
|
+
* @category Functor
|
|
1325
|
+
* @since 2.5.0
|
|
1326
|
+
*/
|
|
1327
|
+
var map = function (f) { return function (fa) {
|
|
1328
|
+
return fa.map(function (a) { return f(a); });
|
|
1329
|
+
}; };
|
|
1330
|
+
exports.map = map;
|
|
1331
|
+
/**
|
|
1332
|
+
* @category FunctorWithIndex
|
|
1333
|
+
* @since 2.5.0
|
|
1334
|
+
*/
|
|
1335
|
+
var mapWithIndex = function (f) { return function (fa) { return fa.map(function (a, i) { return f(i, a); }); }; };
|
|
1336
|
+
exports.mapWithIndex = mapWithIndex;
|
|
1337
|
+
/**
|
|
1338
|
+
* @category Compactable
|
|
1339
|
+
* @since 2.5.0
|
|
1340
|
+
*/
|
|
1341
|
+
var separate = function (fa) {
|
|
1342
|
+
var left = [];
|
|
1343
|
+
var right = [];
|
|
1344
|
+
for (var _i = 0, fa_1 = fa; _i < fa_1.length; _i++) {
|
|
1345
|
+
var e = fa_1[_i];
|
|
1346
|
+
if (e._tag === 'Left') {
|
|
1347
|
+
left.push(e.left);
|
|
1348
|
+
}
|
|
1349
|
+
else {
|
|
1350
|
+
right.push(e.right);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
return (0, Separated.separated)(left, right);
|
|
1354
|
+
};
|
|
1355
|
+
exports.separate = separate;
|
|
1356
|
+
/**
|
|
1357
|
+
* @category Filterable
|
|
1358
|
+
* @since 2.5.0
|
|
1359
|
+
*/
|
|
1360
|
+
var filter = function (predicate) { return function (as) { return as.filter(predicate); }; };
|
|
1361
|
+
exports.filter = filter;
|
|
1362
|
+
/**
|
|
1363
|
+
* @category FilterableWithIndex
|
|
1364
|
+
* @since 2.5.0
|
|
1365
|
+
*/
|
|
1366
|
+
var filterMapWithIndex = function (f) { return function (fa) {
|
|
1367
|
+
var out = [];
|
|
1368
|
+
for (var i = 0; i < fa.length; i++) {
|
|
1369
|
+
var optionB = f(i, fa[i]);
|
|
1370
|
+
if (_.isSome(optionB)) {
|
|
1371
|
+
out.push(optionB.value);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return out;
|
|
1375
|
+
}; };
|
|
1376
|
+
exports.filterMapWithIndex = filterMapWithIndex;
|
|
1377
|
+
/**
|
|
1378
|
+
* @category Filterable
|
|
1379
|
+
* @since 2.5.0
|
|
1380
|
+
*/
|
|
1381
|
+
var filterMap = function (f) {
|
|
1382
|
+
return (0, exports.filterMapWithIndex)(function (_, a) { return f(a); });
|
|
1383
|
+
};
|
|
1384
|
+
exports.filterMap = filterMap;
|
|
1385
|
+
/**
|
|
1386
|
+
* @category Compactable
|
|
1387
|
+
* @since 2.5.0
|
|
1388
|
+
*/
|
|
1389
|
+
exports.compact = (0, exports.filterMap)(_function.identity);
|
|
1390
|
+
/**
|
|
1391
|
+
* @category Filterable
|
|
1392
|
+
* @since 2.5.0
|
|
1393
|
+
*/
|
|
1394
|
+
var partition = function (predicate) {
|
|
1395
|
+
return (0, exports.partitionWithIndex)(function (_, a) { return predicate(a); });
|
|
1396
|
+
};
|
|
1397
|
+
exports.partition = partition;
|
|
1398
|
+
/**
|
|
1399
|
+
* @category FilterableWithIndex
|
|
1400
|
+
* @since 2.5.0
|
|
1401
|
+
*/
|
|
1402
|
+
var partitionWithIndex = function (predicateWithIndex) { return function (as) {
|
|
1403
|
+
var left = [];
|
|
1404
|
+
var right = [];
|
|
1405
|
+
for (var i = 0; i < as.length; i++) {
|
|
1406
|
+
var a = as[i];
|
|
1407
|
+
if (predicateWithIndex(i, a)) {
|
|
1408
|
+
right.push(a);
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
left.push(a);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
return (0, Separated.separated)(left, right);
|
|
1415
|
+
}; };
|
|
1416
|
+
exports.partitionWithIndex = partitionWithIndex;
|
|
1417
|
+
/**
|
|
1418
|
+
* @category Filterable
|
|
1419
|
+
* @since 2.5.0
|
|
1420
|
+
*/
|
|
1421
|
+
var partitionMap = function (f) {
|
|
1422
|
+
return (0, exports.partitionMapWithIndex)(function (_, a) { return f(a); });
|
|
1423
|
+
};
|
|
1424
|
+
exports.partitionMap = partitionMap;
|
|
1425
|
+
/**
|
|
1426
|
+
* @category FilterableWithIndex
|
|
1427
|
+
* @since 2.5.0
|
|
1428
|
+
*/
|
|
1429
|
+
var partitionMapWithIndex = function (f) { return function (fa) {
|
|
1430
|
+
var left = [];
|
|
1431
|
+
var right = [];
|
|
1432
|
+
for (var i = 0; i < fa.length; i++) {
|
|
1433
|
+
var e = f(i, fa[i]);
|
|
1434
|
+
if (e._tag === 'Left') {
|
|
1435
|
+
left.push(e.left);
|
|
1436
|
+
}
|
|
1437
|
+
else {
|
|
1438
|
+
right.push(e.right);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
return (0, Separated.separated)(left, right);
|
|
1442
|
+
}; };
|
|
1443
|
+
exports.partitionMapWithIndex = partitionMapWithIndex;
|
|
1444
|
+
/**
|
|
1445
|
+
* @category FilterableWithIndex
|
|
1446
|
+
* @since 2.5.0
|
|
1447
|
+
*/
|
|
1448
|
+
var filterWithIndex = function (predicateWithIndex) { return function (as) {
|
|
1449
|
+
return as.filter(function (a, i) { return predicateWithIndex(i, a); });
|
|
1450
|
+
}; };
|
|
1451
|
+
exports.filterWithIndex = filterWithIndex;
|
|
1452
|
+
/**
|
|
1453
|
+
* @category Extend
|
|
1454
|
+
* @since 2.5.0
|
|
1455
|
+
*/
|
|
1456
|
+
var extend = function (f) { return function (wa) { return wa.map(function (_, i) { return f(wa.slice(i)); }); }; };
|
|
1457
|
+
exports.extend = extend;
|
|
1458
|
+
/**
|
|
1459
|
+
* Derivable from `Extend`.
|
|
1460
|
+
*
|
|
1461
|
+
* @category combinators
|
|
1462
|
+
* @since 2.5.0
|
|
1463
|
+
*/
|
|
1464
|
+
exports.duplicate = (0, exports.extend)(_function.identity);
|
|
1465
|
+
/**
|
|
1466
|
+
* @category FoldableWithIndex
|
|
1467
|
+
* @since 2.5.0
|
|
1468
|
+
*/
|
|
1469
|
+
var foldMapWithIndex = function (M) { return function (f) { return function (fa) {
|
|
1470
|
+
return fa.reduce(function (b, a, i) { return M.concat(b, f(i, a)); }, M.empty);
|
|
1471
|
+
}; }; };
|
|
1472
|
+
exports.foldMapWithIndex = foldMapWithIndex;
|
|
1473
|
+
/**
|
|
1474
|
+
* @category Foldable
|
|
1475
|
+
* @since 2.5.0
|
|
1476
|
+
*/
|
|
1477
|
+
var reduce = function (b, f) {
|
|
1478
|
+
return (0, exports.reduceWithIndex)(b, function (_, b, a) { return f(b, a); });
|
|
1479
|
+
};
|
|
1480
|
+
exports.reduce = reduce;
|
|
1481
|
+
/**
|
|
1482
|
+
* @category Foldable
|
|
1483
|
+
* @since 2.5.0
|
|
1484
|
+
*/
|
|
1485
|
+
var foldMap = function (M) {
|
|
1486
|
+
var foldMapWithIndexM = (0, exports.foldMapWithIndex)(M);
|
|
1487
|
+
return function (f) { return foldMapWithIndexM(function (_, a) { return f(a); }); };
|
|
1488
|
+
};
|
|
1489
|
+
exports.foldMap = foldMap;
|
|
1490
|
+
/**
|
|
1491
|
+
* @category FoldableWithIndex
|
|
1492
|
+
* @since 2.5.0
|
|
1493
|
+
*/
|
|
1494
|
+
var reduceWithIndex = function (b, f) { return function (fa) {
|
|
1495
|
+
var len = fa.length;
|
|
1496
|
+
var out = b;
|
|
1497
|
+
for (var i = 0; i < len; i++) {
|
|
1498
|
+
out = f(i, out, fa[i]);
|
|
1499
|
+
}
|
|
1500
|
+
return out;
|
|
1501
|
+
}; };
|
|
1502
|
+
exports.reduceWithIndex = reduceWithIndex;
|
|
1503
|
+
/**
|
|
1504
|
+
* @category Foldable
|
|
1505
|
+
* @since 2.5.0
|
|
1506
|
+
*/
|
|
1507
|
+
var reduceRight = function (b, f) {
|
|
1508
|
+
return (0, exports.reduceRightWithIndex)(b, function (_, a, b) { return f(a, b); });
|
|
1509
|
+
};
|
|
1510
|
+
exports.reduceRight = reduceRight;
|
|
1511
|
+
/**
|
|
1512
|
+
* @category FoldableWithIndex
|
|
1513
|
+
* @since 2.5.0
|
|
1514
|
+
*/
|
|
1515
|
+
var reduceRightWithIndex = function (b, f) { return function (fa) { return fa.reduceRight(function (b, a, i) { return f(i, a, b); }, b); }; };
|
|
1516
|
+
exports.reduceRightWithIndex = reduceRightWithIndex;
|
|
1517
|
+
/**
|
|
1518
|
+
* @category Traversable
|
|
1519
|
+
* @since 2.6.3
|
|
1520
|
+
*/
|
|
1521
|
+
var traverse = function (F) {
|
|
1522
|
+
var traverseWithIndexF = (0, exports.traverseWithIndex)(F);
|
|
1523
|
+
return function (f) { return traverseWithIndexF(function (_, a) { return f(a); }); };
|
|
1524
|
+
};
|
|
1525
|
+
exports.traverse = traverse;
|
|
1526
|
+
/**
|
|
1527
|
+
* @category Traversable
|
|
1528
|
+
* @since 2.6.3
|
|
1529
|
+
*/
|
|
1530
|
+
var sequence = function (F) { return function (ta) {
|
|
1531
|
+
return _reduce(ta, F.of((0, exports.zero)()), function (fas, fa) {
|
|
1532
|
+
return F.ap(F.map(fas, function (as) { return function (a) { return (0, _function.pipe)(as, (0, exports.append)(a)); }; }), fa);
|
|
1533
|
+
});
|
|
1534
|
+
}; };
|
|
1535
|
+
exports.sequence = sequence;
|
|
1536
|
+
/**
|
|
1537
|
+
* @category TraversableWithIndex
|
|
1538
|
+
* @since 2.6.3
|
|
1539
|
+
*/
|
|
1540
|
+
var traverseWithIndex = function (F) { return function (f) {
|
|
1541
|
+
return (0, exports.reduceWithIndex)(F.of((0, exports.zero)()), function (i, fbs, a) {
|
|
1542
|
+
return F.ap(F.map(fbs, function (bs) { return function (b) { return (0, _function.pipe)(bs, (0, exports.append)(b)); }; }), f(i, a));
|
|
1543
|
+
});
|
|
1544
|
+
}; };
|
|
1545
|
+
exports.traverseWithIndex = traverseWithIndex;
|
|
1546
|
+
/**
|
|
1547
|
+
* @category Witherable
|
|
1548
|
+
* @since 2.6.5
|
|
1549
|
+
*/
|
|
1550
|
+
var wither = function (F) {
|
|
1551
|
+
var _witherF = _wither(F);
|
|
1552
|
+
return function (f) { return function (fa) { return _witherF(fa, f); }; };
|
|
1553
|
+
};
|
|
1554
|
+
exports.wither = wither;
|
|
1555
|
+
/**
|
|
1556
|
+
* @category Witherable
|
|
1557
|
+
* @since 2.6.5
|
|
1558
|
+
*/
|
|
1559
|
+
var wilt = function (F) {
|
|
1560
|
+
var _wiltF = _wilt(F);
|
|
1561
|
+
return function (f) { return function (fa) { return _wiltF(fa, f); }; };
|
|
1562
|
+
};
|
|
1563
|
+
exports.wilt = wilt;
|
|
1564
|
+
/**
|
|
1565
|
+
* @category Unfoldable
|
|
1566
|
+
* @since 2.6.6
|
|
1567
|
+
*/
|
|
1568
|
+
var unfold = function (b, f) {
|
|
1569
|
+
var out = [];
|
|
1570
|
+
var bb = b;
|
|
1571
|
+
// eslint-disable-next-line no-constant-condition
|
|
1572
|
+
while (true) {
|
|
1573
|
+
var mt = f(bb);
|
|
1574
|
+
if (_.isSome(mt)) {
|
|
1575
|
+
var _a = mt.value, a = _a[0], b_1 = _a[1];
|
|
1576
|
+
out.push(a);
|
|
1577
|
+
bb = b_1;
|
|
1578
|
+
}
|
|
1579
|
+
else {
|
|
1580
|
+
break;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
return out;
|
|
1584
|
+
};
|
|
1585
|
+
exports.unfold = unfold;
|
|
1586
|
+
// -------------------------------------------------------------------------------------
|
|
1587
|
+
// instances
|
|
1588
|
+
// -------------------------------------------------------------------------------------
|
|
1589
|
+
/**
|
|
1590
|
+
* @category instances
|
|
1591
|
+
* @since 2.5.0
|
|
1592
|
+
*/
|
|
1593
|
+
exports.URI = 'ReadonlyArray';
|
|
1594
|
+
/**
|
|
1595
|
+
* @category instances
|
|
1596
|
+
* @since 2.5.0
|
|
1597
|
+
*/
|
|
1598
|
+
var getShow = function (S) { return ({
|
|
1599
|
+
show: function (as) { return "[".concat(as.map(S.show).join(', '), "]"); }
|
|
1600
|
+
}); };
|
|
1601
|
+
exports.getShow = getShow;
|
|
1602
|
+
/**
|
|
1603
|
+
* @category instances
|
|
1604
|
+
* @since 2.5.0
|
|
1605
|
+
*/
|
|
1606
|
+
var getSemigroup = function () { return ({
|
|
1607
|
+
concat: function (first, second) { return ((0, exports.isEmpty)(first) ? second : (0, exports.isEmpty)(second) ? first : first.concat(second)); }
|
|
1608
|
+
}); };
|
|
1609
|
+
exports.getSemigroup = getSemigroup;
|
|
1610
|
+
/**
|
|
1611
|
+
* Returns a `Monoid` for `ReadonlyArray<A>`.
|
|
1612
|
+
*
|
|
1613
|
+
* @example
|
|
1614
|
+
* import { getMonoid } from 'fp-ts/ReadonlyArray'
|
|
1615
|
+
*
|
|
1616
|
+
* const M = getMonoid<number>()
|
|
1617
|
+
* assert.deepStrictEqual(M.concat([1, 2], [3, 4]), [1, 2, 3, 4])
|
|
1618
|
+
*
|
|
1619
|
+
* @category instances
|
|
1620
|
+
* @since 2.5.0
|
|
1621
|
+
*/
|
|
1622
|
+
var getMonoid = function () { return ({
|
|
1623
|
+
concat: (0, exports.getSemigroup)().concat,
|
|
1624
|
+
empty: exports.empty
|
|
1625
|
+
}); };
|
|
1626
|
+
exports.getMonoid = getMonoid;
|
|
1627
|
+
/**
|
|
1628
|
+
* Derives an `Eq` over the `ReadonlyArray` of a given element type from the `Eq` of that type. The derived `Eq` defines two
|
|
1629
|
+
* arrays as equal if all elements of both arrays are compared equal pairwise with the given `E`. In case of arrays of
|
|
1630
|
+
* different lengths, the result is non equality.
|
|
1631
|
+
*
|
|
1632
|
+
* @example
|
|
1633
|
+
* import * as S from 'fp-ts/string'
|
|
1634
|
+
* import { getEq } from 'fp-ts/ReadonlyArray'
|
|
1635
|
+
*
|
|
1636
|
+
* const E = getEq(S.Eq)
|
|
1637
|
+
* assert.strictEqual(E.equals(['a', 'b'], ['a', 'b']), true)
|
|
1638
|
+
* assert.strictEqual(E.equals(['a'], []), false)
|
|
1639
|
+
*
|
|
1640
|
+
* @category instances
|
|
1641
|
+
* @since 2.5.0
|
|
1642
|
+
*/
|
|
1643
|
+
var getEq = function (E) {
|
|
1644
|
+
return (0, Eq.fromEquals)(function (xs, ys) { return xs.length === ys.length && xs.every(function (x, i) { return E.equals(x, ys[i]); }); });
|
|
1645
|
+
};
|
|
1646
|
+
exports.getEq = getEq;
|
|
1647
|
+
/**
|
|
1648
|
+
* Derives an `Ord` over the `ReadonlyArray` of a given element type from the `Ord` of that type. The ordering between two such
|
|
1649
|
+
* arrays is equal to: the first non equal comparison of each arrays elements taken pairwise in increasing order, in
|
|
1650
|
+
* case of equality over all the pairwise elements; the longest array is considered the greatest, if both arrays have
|
|
1651
|
+
* the same length, the result is equality.
|
|
1652
|
+
*
|
|
1653
|
+
* @example
|
|
1654
|
+
* import { getOrd } from 'fp-ts/ReadonlyArray'
|
|
1655
|
+
* import * as S from 'fp-ts/string'
|
|
1656
|
+
*
|
|
1657
|
+
* const O = getOrd(S.Ord)
|
|
1658
|
+
* assert.strictEqual(O.compare(['b'], ['a']), 1)
|
|
1659
|
+
* assert.strictEqual(O.compare(['a'], ['a']), 0)
|
|
1660
|
+
* assert.strictEqual(O.compare(['a'], ['b']), -1)
|
|
1661
|
+
*
|
|
1662
|
+
*
|
|
1663
|
+
* @category instances
|
|
1664
|
+
* @since 2.5.0
|
|
1665
|
+
*/
|
|
1666
|
+
var getOrd = function (O) {
|
|
1667
|
+
return (0, Ord.fromCompare)(function (a, b) {
|
|
1668
|
+
var aLen = a.length;
|
|
1669
|
+
var bLen = b.length;
|
|
1670
|
+
var len = Math.min(aLen, bLen);
|
|
1671
|
+
for (var i = 0; i < len; i++) {
|
|
1672
|
+
var ordering = O.compare(a[i], b[i]);
|
|
1673
|
+
if (ordering !== 0) {
|
|
1674
|
+
return ordering;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return N.Ord.compare(aLen, bLen);
|
|
1678
|
+
});
|
|
1679
|
+
};
|
|
1680
|
+
exports.getOrd = getOrd;
|
|
1681
|
+
/**
|
|
1682
|
+
* @category instances
|
|
1683
|
+
* @since 2.11.0
|
|
1684
|
+
*/
|
|
1685
|
+
var getUnionSemigroup = function (E) {
|
|
1686
|
+
var unionE = union(E);
|
|
1687
|
+
return {
|
|
1688
|
+
concat: function (first, second) { return unionE(second)(first); }
|
|
1689
|
+
};
|
|
1690
|
+
};
|
|
1691
|
+
exports.getUnionSemigroup = getUnionSemigroup;
|
|
1692
|
+
/**
|
|
1693
|
+
* @category instances
|
|
1694
|
+
* @since 2.11.0
|
|
1695
|
+
*/
|
|
1696
|
+
var getUnionMonoid = function (E) { return ({
|
|
1697
|
+
concat: (0, exports.getUnionSemigroup)(E).concat,
|
|
1698
|
+
empty: exports.empty
|
|
1699
|
+
}); };
|
|
1700
|
+
exports.getUnionMonoid = getUnionMonoid;
|
|
1701
|
+
/**
|
|
1702
|
+
* @category instances
|
|
1703
|
+
* @since 2.11.0
|
|
1704
|
+
*/
|
|
1705
|
+
var getIntersectionSemigroup = function (E) {
|
|
1706
|
+
var intersectionE = intersection(E);
|
|
1707
|
+
return {
|
|
1708
|
+
concat: function (first, second) { return intersectionE(second)(first); }
|
|
1709
|
+
};
|
|
1710
|
+
};
|
|
1711
|
+
exports.getIntersectionSemigroup = getIntersectionSemigroup;
|
|
1712
|
+
/**
|
|
1713
|
+
* @category instances
|
|
1714
|
+
* @since 2.11.0
|
|
1715
|
+
*/
|
|
1716
|
+
var getDifferenceMagma = function (E) {
|
|
1717
|
+
var differenceE = difference(E);
|
|
1718
|
+
return {
|
|
1719
|
+
concat: function (first, second) { return differenceE(second)(first); }
|
|
1720
|
+
};
|
|
1721
|
+
};
|
|
1722
|
+
exports.getDifferenceMagma = getDifferenceMagma;
|
|
1723
|
+
/**
|
|
1724
|
+
* @category instances
|
|
1725
|
+
* @since 2.7.0
|
|
1726
|
+
*/
|
|
1727
|
+
exports.Functor = {
|
|
1728
|
+
URI: exports.URI,
|
|
1729
|
+
map: _map
|
|
1730
|
+
};
|
|
1731
|
+
/**
|
|
1732
|
+
* Derivable from `Functor`.
|
|
1733
|
+
*
|
|
1734
|
+
* @category combinators
|
|
1735
|
+
* @since 2.10.0
|
|
1736
|
+
*/
|
|
1737
|
+
exports.flap = (0, Functor.flap)(exports.Functor);
|
|
1738
|
+
/**
|
|
1739
|
+
* @category instances
|
|
1740
|
+
* @since 2.10.0
|
|
1741
|
+
*/
|
|
1742
|
+
exports.Pointed = {
|
|
1743
|
+
URI: exports.URI,
|
|
1744
|
+
of: exports.of
|
|
1745
|
+
};
|
|
1746
|
+
/**
|
|
1747
|
+
* @category instances
|
|
1748
|
+
* @since 2.7.0
|
|
1749
|
+
*/
|
|
1750
|
+
exports.FunctorWithIndex = {
|
|
1751
|
+
URI: exports.URI,
|
|
1752
|
+
map: _map,
|
|
1753
|
+
mapWithIndex: _mapWithIndex
|
|
1754
|
+
};
|
|
1755
|
+
/**
|
|
1756
|
+
* @category instances
|
|
1757
|
+
* @since 2.10.0
|
|
1758
|
+
*/
|
|
1759
|
+
exports.Apply = {
|
|
1760
|
+
URI: exports.URI,
|
|
1761
|
+
map: _map,
|
|
1762
|
+
ap: _ap
|
|
1763
|
+
};
|
|
1764
|
+
/**
|
|
1765
|
+
* Combine two effectful actions, keeping only the result of the first.
|
|
1766
|
+
*
|
|
1767
|
+
* Derivable from `Apply`.
|
|
1768
|
+
*
|
|
1769
|
+
* @category combinators
|
|
1770
|
+
* @since 2.5.0
|
|
1771
|
+
*/
|
|
1772
|
+
exports.apFirst = (0, Apply.apFirst)(exports.Apply);
|
|
1773
|
+
/**
|
|
1774
|
+
* Combine two effectful actions, keeping only the result of the second.
|
|
1775
|
+
*
|
|
1776
|
+
* Derivable from `Apply`.
|
|
1777
|
+
*
|
|
1778
|
+
* @category combinators
|
|
1779
|
+
* @since 2.5.0
|
|
1780
|
+
*/
|
|
1781
|
+
exports.apSecond = (0, Apply.apSecond)(exports.Apply);
|
|
1782
|
+
/**
|
|
1783
|
+
* @category instances
|
|
1784
|
+
* @since 2.7.0
|
|
1785
|
+
*/
|
|
1786
|
+
exports.Applicative = {
|
|
1787
|
+
URI: exports.URI,
|
|
1788
|
+
map: _map,
|
|
1789
|
+
ap: _ap,
|
|
1790
|
+
of: exports.of
|
|
1791
|
+
};
|
|
1792
|
+
/**
|
|
1793
|
+
* @category instances
|
|
1794
|
+
* @since 2.10.0
|
|
1795
|
+
*/
|
|
1796
|
+
exports.Chain = {
|
|
1797
|
+
URI: exports.URI,
|
|
1798
|
+
map: _map,
|
|
1799
|
+
ap: _ap,
|
|
1800
|
+
chain: _chain
|
|
1801
|
+
};
|
|
1802
|
+
/**
|
|
1803
|
+
* @category instances
|
|
1804
|
+
* @since 2.7.0
|
|
1805
|
+
*/
|
|
1806
|
+
exports.Monad = {
|
|
1807
|
+
URI: exports.URI,
|
|
1808
|
+
map: _map,
|
|
1809
|
+
ap: _ap,
|
|
1810
|
+
of: exports.of,
|
|
1811
|
+
chain: _chain
|
|
1812
|
+
};
|
|
1813
|
+
/**
|
|
1814
|
+
* Composes computations in sequence, using the return value of one computation to determine the next computation and
|
|
1815
|
+
* keeping only the result of the first.
|
|
1816
|
+
*
|
|
1817
|
+
* Derivable from `Chain`.
|
|
1818
|
+
*
|
|
1819
|
+
* @category combinators
|
|
1820
|
+
* @since 2.5.0
|
|
1821
|
+
*/
|
|
1822
|
+
exports.chainFirst = (0, Chain.chainFirst)(exports.Chain);
|
|
1823
|
+
/**
|
|
1824
|
+
* @category instances
|
|
1825
|
+
* @since 2.7.0
|
|
1826
|
+
*/
|
|
1827
|
+
exports.Unfoldable = {
|
|
1828
|
+
URI: exports.URI,
|
|
1829
|
+
unfold: exports.unfold
|
|
1830
|
+
};
|
|
1831
|
+
/**
|
|
1832
|
+
* @category instances
|
|
1833
|
+
* @since 2.7.0
|
|
1834
|
+
*/
|
|
1835
|
+
exports.Alt = {
|
|
1836
|
+
URI: exports.URI,
|
|
1837
|
+
map: _map,
|
|
1838
|
+
alt: _alt
|
|
1839
|
+
};
|
|
1840
|
+
/**
|
|
1841
|
+
* @category instances
|
|
1842
|
+
* @since 2.11.0
|
|
1843
|
+
*/
|
|
1844
|
+
exports.Zero = {
|
|
1845
|
+
URI: exports.URI,
|
|
1846
|
+
zero: exports.zero
|
|
1847
|
+
};
|
|
1848
|
+
/**
|
|
1849
|
+
* @category constructors
|
|
1850
|
+
* @since 2.11.0
|
|
1851
|
+
*/
|
|
1852
|
+
exports.guard = (0, Zero.guard)(exports.Zero, exports.Pointed);
|
|
1853
|
+
/**
|
|
1854
|
+
* @category instances
|
|
1855
|
+
* @since 2.7.0
|
|
1856
|
+
*/
|
|
1857
|
+
exports.Alternative = {
|
|
1858
|
+
URI: exports.URI,
|
|
1859
|
+
map: _map,
|
|
1860
|
+
ap: _ap,
|
|
1861
|
+
of: exports.of,
|
|
1862
|
+
alt: _alt,
|
|
1863
|
+
zero: exports.zero
|
|
1864
|
+
};
|
|
1865
|
+
/**
|
|
1866
|
+
* @category instances
|
|
1867
|
+
* @since 2.7.0
|
|
1868
|
+
*/
|
|
1869
|
+
exports.Extend = {
|
|
1870
|
+
URI: exports.URI,
|
|
1871
|
+
map: _map,
|
|
1872
|
+
extend: _extend
|
|
1873
|
+
};
|
|
1874
|
+
/**
|
|
1875
|
+
* @category instances
|
|
1876
|
+
* @since 2.7.0
|
|
1877
|
+
*/
|
|
1878
|
+
exports.Compactable = {
|
|
1879
|
+
URI: exports.URI,
|
|
1880
|
+
compact: exports.compact,
|
|
1881
|
+
separate: exports.separate
|
|
1882
|
+
};
|
|
1883
|
+
/**
|
|
1884
|
+
* @category instances
|
|
1885
|
+
* @since 2.7.0
|
|
1886
|
+
*/
|
|
1887
|
+
exports.Filterable = {
|
|
1888
|
+
URI: exports.URI,
|
|
1889
|
+
map: _map,
|
|
1890
|
+
compact: exports.compact,
|
|
1891
|
+
separate: exports.separate,
|
|
1892
|
+
filter: _filter,
|
|
1893
|
+
filterMap: _filterMap,
|
|
1894
|
+
partition: _partition,
|
|
1895
|
+
partitionMap: _partitionMap
|
|
1896
|
+
};
|
|
1897
|
+
/**
|
|
1898
|
+
* @category instances
|
|
1899
|
+
* @since 2.7.0
|
|
1900
|
+
*/
|
|
1901
|
+
exports.FilterableWithIndex = {
|
|
1902
|
+
URI: exports.URI,
|
|
1903
|
+
map: _map,
|
|
1904
|
+
mapWithIndex: _mapWithIndex,
|
|
1905
|
+
compact: exports.compact,
|
|
1906
|
+
separate: exports.separate,
|
|
1907
|
+
filter: _filter,
|
|
1908
|
+
filterMap: _filterMap,
|
|
1909
|
+
partition: _partition,
|
|
1910
|
+
partitionMap: _partitionMap,
|
|
1911
|
+
partitionMapWithIndex: _partitionMapWithIndex,
|
|
1912
|
+
partitionWithIndex: _partitionWithIndex,
|
|
1913
|
+
filterMapWithIndex: _filterMapWithIndex,
|
|
1914
|
+
filterWithIndex: _filterWithIndex
|
|
1915
|
+
};
|
|
1916
|
+
/**
|
|
1917
|
+
* @category instances
|
|
1918
|
+
* @since 2.7.0
|
|
1919
|
+
*/
|
|
1920
|
+
exports.Foldable = {
|
|
1921
|
+
URI: exports.URI,
|
|
1922
|
+
reduce: _reduce,
|
|
1923
|
+
foldMap: _foldMap,
|
|
1924
|
+
reduceRight: _reduceRight
|
|
1925
|
+
};
|
|
1926
|
+
/**
|
|
1927
|
+
* @category instances
|
|
1928
|
+
* @since 2.7.0
|
|
1929
|
+
*/
|
|
1930
|
+
exports.FoldableWithIndex = {
|
|
1931
|
+
URI: exports.URI,
|
|
1932
|
+
reduce: _reduce,
|
|
1933
|
+
foldMap: _foldMap,
|
|
1934
|
+
reduceRight: _reduceRight,
|
|
1935
|
+
reduceWithIndex: _reduceWithIndex,
|
|
1936
|
+
foldMapWithIndex: _foldMapWithIndex,
|
|
1937
|
+
reduceRightWithIndex: _reduceRightWithIndex
|
|
1938
|
+
};
|
|
1939
|
+
/**
|
|
1940
|
+
* @category instances
|
|
1941
|
+
* @since 2.7.0
|
|
1942
|
+
*/
|
|
1943
|
+
exports.Traversable = {
|
|
1944
|
+
URI: exports.URI,
|
|
1945
|
+
map: _map,
|
|
1946
|
+
reduce: _reduce,
|
|
1947
|
+
foldMap: _foldMap,
|
|
1948
|
+
reduceRight: _reduceRight,
|
|
1949
|
+
traverse: _traverse,
|
|
1950
|
+
sequence: exports.sequence
|
|
1951
|
+
};
|
|
1952
|
+
/**
|
|
1953
|
+
* @category instances
|
|
1954
|
+
* @since 2.7.0
|
|
1955
|
+
*/
|
|
1956
|
+
exports.TraversableWithIndex = {
|
|
1957
|
+
URI: exports.URI,
|
|
1958
|
+
map: _map,
|
|
1959
|
+
mapWithIndex: _mapWithIndex,
|
|
1960
|
+
reduce: _reduce,
|
|
1961
|
+
foldMap: _foldMap,
|
|
1962
|
+
reduceRight: _reduceRight,
|
|
1963
|
+
reduceWithIndex: _reduceWithIndex,
|
|
1964
|
+
foldMapWithIndex: _foldMapWithIndex,
|
|
1965
|
+
reduceRightWithIndex: _reduceRightWithIndex,
|
|
1966
|
+
traverse: _traverse,
|
|
1967
|
+
sequence: exports.sequence,
|
|
1968
|
+
traverseWithIndex: _traverseWithIndex
|
|
1969
|
+
};
|
|
1970
|
+
/**
|
|
1971
|
+
* @category ChainRec
|
|
1972
|
+
* @since 2.11.0
|
|
1973
|
+
*/
|
|
1974
|
+
var chainRecDepthFirst = function (f) { return function (a) {
|
|
1975
|
+
var todo = __spreadArray([], f(a), true);
|
|
1976
|
+
var out = [];
|
|
1977
|
+
while (todo.length > 0) {
|
|
1978
|
+
var e = todo.shift();
|
|
1979
|
+
if (_.isLeft(e)) {
|
|
1980
|
+
todo.unshift.apply(todo, f(e.left));
|
|
1981
|
+
}
|
|
1982
|
+
else {
|
|
1983
|
+
out.push(e.right);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
return out;
|
|
1987
|
+
}; };
|
|
1988
|
+
exports.chainRecDepthFirst = chainRecDepthFirst;
|
|
1989
|
+
/**
|
|
1990
|
+
* @category instances
|
|
1991
|
+
* @since 2.11.0
|
|
1992
|
+
*/
|
|
1993
|
+
exports.ChainRecDepthFirst = {
|
|
1994
|
+
URI: exports.URI,
|
|
1995
|
+
map: _map,
|
|
1996
|
+
ap: _ap,
|
|
1997
|
+
chain: _chain,
|
|
1998
|
+
chainRec: exports._chainRecDepthFirst
|
|
1999
|
+
};
|
|
2000
|
+
/**
|
|
2001
|
+
* @category ChainRec
|
|
2002
|
+
* @since 2.11.0
|
|
2003
|
+
*/
|
|
2004
|
+
var chainRecBreadthFirst = function (f) { return function (a) {
|
|
2005
|
+
var initial = f(a);
|
|
2006
|
+
var todo = [];
|
|
2007
|
+
var out = [];
|
|
2008
|
+
function go(e) {
|
|
2009
|
+
if (_.isLeft(e)) {
|
|
2010
|
+
f(e.left).forEach(function (v) { return todo.push(v); });
|
|
2011
|
+
}
|
|
2012
|
+
else {
|
|
2013
|
+
out.push(e.right);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
for (var _i = 0, initial_1 = initial; _i < initial_1.length; _i++) {
|
|
2017
|
+
var e = initial_1[_i];
|
|
2018
|
+
go(e);
|
|
2019
|
+
}
|
|
2020
|
+
while (todo.length > 0) {
|
|
2021
|
+
go(todo.shift());
|
|
2022
|
+
}
|
|
2023
|
+
return out;
|
|
2024
|
+
}; };
|
|
2025
|
+
exports.chainRecBreadthFirst = chainRecBreadthFirst;
|
|
2026
|
+
/**
|
|
2027
|
+
* @category instances
|
|
2028
|
+
* @since 2.11.0
|
|
2029
|
+
*/
|
|
2030
|
+
exports.ChainRecBreadthFirst = {
|
|
2031
|
+
URI: exports.URI,
|
|
2032
|
+
map: _map,
|
|
2033
|
+
ap: _ap,
|
|
2034
|
+
chain: _chain,
|
|
2035
|
+
chainRec: exports._chainRecBreadthFirst
|
|
2036
|
+
};
|
|
2037
|
+
var _wither = /*#__PURE__*/ (0, Witherable.witherDefault)(exports.Traversable, exports.Compactable);
|
|
2038
|
+
var _wilt = /*#__PURE__*/ (0, Witherable.wiltDefault)(exports.Traversable, exports.Compactable);
|
|
2039
|
+
/**
|
|
2040
|
+
* @category instances
|
|
2041
|
+
* @since 2.7.0
|
|
2042
|
+
*/
|
|
2043
|
+
exports.Witherable = {
|
|
2044
|
+
URI: exports.URI,
|
|
2045
|
+
map: _map,
|
|
2046
|
+
compact: exports.compact,
|
|
2047
|
+
separate: exports.separate,
|
|
2048
|
+
filter: _filter,
|
|
2049
|
+
filterMap: _filterMap,
|
|
2050
|
+
partition: _partition,
|
|
2051
|
+
partitionMap: _partitionMap,
|
|
2052
|
+
reduce: _reduce,
|
|
2053
|
+
foldMap: _foldMap,
|
|
2054
|
+
reduceRight: _reduceRight,
|
|
2055
|
+
traverse: _traverse,
|
|
2056
|
+
sequence: exports.sequence,
|
|
2057
|
+
wither: _wither,
|
|
2058
|
+
wilt: _wilt
|
|
2059
|
+
};
|
|
2060
|
+
/**
|
|
2061
|
+
* Filter values inside a context.
|
|
2062
|
+
*
|
|
2063
|
+
* @example
|
|
2064
|
+
* import { pipe } from 'fp-ts/function'
|
|
2065
|
+
* import * as RA from 'fp-ts/ReadonlyArray'
|
|
2066
|
+
* import * as T from 'fp-ts/Task'
|
|
2067
|
+
*
|
|
2068
|
+
* const filterE = RA.filterE(T.ApplicativePar)
|
|
2069
|
+
* async function test() {
|
|
2070
|
+
* assert.deepStrictEqual(
|
|
2071
|
+
* await pipe(
|
|
2072
|
+
* [-1, 2, 3],
|
|
2073
|
+
* filterE((n) => T.of(n > 0))
|
|
2074
|
+
* )(),
|
|
2075
|
+
* [2, 3]
|
|
2076
|
+
* )
|
|
2077
|
+
* }
|
|
2078
|
+
* test()
|
|
2079
|
+
*
|
|
2080
|
+
* @since 2.11.0
|
|
2081
|
+
*/
|
|
2082
|
+
exports.filterE = (0, Witherable.filterE)(exports.Witherable);
|
|
2083
|
+
/**
|
|
2084
|
+
* @category instances
|
|
2085
|
+
* @since 2.11.0
|
|
2086
|
+
*/
|
|
2087
|
+
exports.FromEither = {
|
|
2088
|
+
URI: exports.URI,
|
|
2089
|
+
fromEither: exports.fromEither
|
|
2090
|
+
};
|
|
2091
|
+
/**
|
|
2092
|
+
* @category combinators
|
|
2093
|
+
* @since 2.11.0
|
|
2094
|
+
*/
|
|
2095
|
+
exports.fromEitherK = (0, FromEither.fromEitherK)(exports.FromEither);
|
|
2096
|
+
// -------------------------------------------------------------------------------------
|
|
2097
|
+
// unsafe
|
|
2098
|
+
// -------------------------------------------------------------------------------------
|
|
2099
|
+
/**
|
|
2100
|
+
* @category unsafe
|
|
2101
|
+
* @since 2.5.0
|
|
2102
|
+
*/
|
|
2103
|
+
exports.unsafeInsertAt = RNEA.unsafeInsertAt;
|
|
2104
|
+
/**
|
|
2105
|
+
* @category unsafe
|
|
2106
|
+
* @since 2.5.0
|
|
2107
|
+
*/
|
|
2108
|
+
var unsafeUpdateAt = function (i, a, as) {
|
|
2109
|
+
return (0, exports.isNonEmpty)(as) ? RNEA.unsafeUpdateAt(i, a, as) : as;
|
|
2110
|
+
};
|
|
2111
|
+
exports.unsafeUpdateAt = unsafeUpdateAt;
|
|
2112
|
+
/**
|
|
2113
|
+
* @category unsafe
|
|
2114
|
+
* @since 2.5.0
|
|
2115
|
+
*/
|
|
2116
|
+
var unsafeDeleteAt = function (i, as) {
|
|
2117
|
+
var xs = as.slice();
|
|
2118
|
+
xs.splice(i, 1);
|
|
2119
|
+
return xs;
|
|
2120
|
+
};
|
|
2121
|
+
exports.unsafeDeleteAt = unsafeDeleteAt;
|
|
2122
|
+
// -------------------------------------------------------------------------------------
|
|
2123
|
+
// interop
|
|
2124
|
+
// -------------------------------------------------------------------------------------
|
|
2125
|
+
/**
|
|
2126
|
+
* @category interop
|
|
2127
|
+
* @since 2.5.0
|
|
2128
|
+
*/
|
|
2129
|
+
var toArray = function (as) { return as.slice(); };
|
|
2130
|
+
exports.toArray = toArray;
|
|
2131
|
+
/**
|
|
2132
|
+
* @category interop
|
|
2133
|
+
* @since 2.5.0
|
|
2134
|
+
*/
|
|
2135
|
+
var fromArray = function (as) { return ((0, exports.isEmpty)(as) ? exports.empty : as.slice()); };
|
|
2136
|
+
exports.fromArray = fromArray;
|
|
2137
|
+
// -------------------------------------------------------------------------------------
|
|
2138
|
+
// utils
|
|
2139
|
+
// -------------------------------------------------------------------------------------
|
|
2140
|
+
/**
|
|
2141
|
+
* An empty array
|
|
2142
|
+
*
|
|
2143
|
+
* @since 2.5.0
|
|
2144
|
+
*/
|
|
2145
|
+
exports.empty = RNEA.empty;
|
|
2146
|
+
function every(predicate) {
|
|
2147
|
+
return function (as) { return as.every(predicate); };
|
|
2148
|
+
}
|
|
2149
|
+
exports.every = every;
|
|
2150
|
+
/**
|
|
2151
|
+
* Check if a predicate holds true for any array member.
|
|
2152
|
+
*
|
|
2153
|
+
* @example
|
|
2154
|
+
* import { some } from 'fp-ts/ReadonlyArray'
|
|
2155
|
+
* import { pipe } from 'fp-ts/function'
|
|
2156
|
+
*
|
|
2157
|
+
* const isPositive = (n: number): boolean => n > 0
|
|
2158
|
+
*
|
|
2159
|
+
* assert.deepStrictEqual(pipe([-1, -2, 3], some(isPositive)), true)
|
|
2160
|
+
* assert.deepStrictEqual(pipe([-1, -2, -3], some(isPositive)), false)
|
|
2161
|
+
*
|
|
2162
|
+
* @since 2.9.0
|
|
2163
|
+
*/
|
|
2164
|
+
var some = function (predicate) { return function (as) {
|
|
2165
|
+
return as.some(predicate);
|
|
2166
|
+
}; };
|
|
2167
|
+
exports.some = some;
|
|
2168
|
+
/**
|
|
2169
|
+
* Alias of [`some`](#some)
|
|
2170
|
+
*
|
|
2171
|
+
* @since 2.11.0
|
|
2172
|
+
*/
|
|
2173
|
+
exports.exists = exports.some;
|
|
2174
|
+
/**
|
|
2175
|
+
* Places an element in between members of a `ReadonlyArray`, then folds the results using the provided `Monoid`.
|
|
2176
|
+
*
|
|
2177
|
+
* @example
|
|
2178
|
+
* import * as S from 'fp-ts/string'
|
|
2179
|
+
* import { intercalate } from 'fp-ts/ReadonlyArray'
|
|
2180
|
+
*
|
|
2181
|
+
* assert.deepStrictEqual(intercalate(S.Monoid)('-')(['a', 'b', 'c']), 'a-b-c')
|
|
2182
|
+
*
|
|
2183
|
+
* @since 2.12.0
|
|
2184
|
+
*/
|
|
2185
|
+
var intercalate = function (M) {
|
|
2186
|
+
var intercalateM = RNEA.intercalate(M);
|
|
2187
|
+
return function (middle) { return (0, exports.match)(function () { return M.empty; }, intercalateM(middle)); };
|
|
2188
|
+
};
|
|
2189
|
+
exports.intercalate = intercalate;
|
|
2190
|
+
// -------------------------------------------------------------------------------------
|
|
2191
|
+
// do notation
|
|
2192
|
+
// -------------------------------------------------------------------------------------
|
|
2193
|
+
/**
|
|
2194
|
+
* @since 2.9.0
|
|
2195
|
+
*/
|
|
2196
|
+
exports.Do = (0, exports.of)(_.emptyRecord);
|
|
2197
|
+
/**
|
|
2198
|
+
* @since 2.8.0
|
|
2199
|
+
*/
|
|
2200
|
+
exports.bindTo = (0, Functor.bindTo)(exports.Functor);
|
|
2201
|
+
/**
|
|
2202
|
+
* @since 2.8.0
|
|
2203
|
+
*/
|
|
2204
|
+
exports.bind = (0, Chain.bind)(exports.Chain);
|
|
2205
|
+
// -------------------------------------------------------------------------------------
|
|
2206
|
+
// pipeable sequence S
|
|
2207
|
+
// -------------------------------------------------------------------------------------
|
|
2208
|
+
/**
|
|
2209
|
+
* @since 2.8.0
|
|
2210
|
+
*/
|
|
2211
|
+
exports.apS = (0, Apply.apS)(exports.Apply);
|
|
2212
|
+
// -------------------------------------------------------------------------------------
|
|
2213
|
+
// deprecated
|
|
2214
|
+
// -------------------------------------------------------------------------------------
|
|
2215
|
+
/**
|
|
2216
|
+
* Use `ReadonlyNonEmptyArray` module instead.
|
|
2217
|
+
*
|
|
2218
|
+
* @category constructors
|
|
2219
|
+
* @since 2.5.0
|
|
2220
|
+
* @deprecated
|
|
2221
|
+
*/
|
|
2222
|
+
exports.range = RNEA.range;
|
|
2223
|
+
/**
|
|
2224
|
+
* Use [`prepend`](#prepend) instead.
|
|
2225
|
+
*
|
|
2226
|
+
* @category constructors
|
|
2227
|
+
* @since 2.5.0
|
|
2228
|
+
* @deprecated
|
|
2229
|
+
*/
|
|
2230
|
+
exports.cons = RNEA.cons;
|
|
2231
|
+
/**
|
|
2232
|
+
* Use [`append`](#append) instead.
|
|
2233
|
+
*
|
|
2234
|
+
* @category constructors
|
|
2235
|
+
* @since 2.5.0
|
|
2236
|
+
* @deprecated
|
|
2237
|
+
*/
|
|
2238
|
+
exports.snoc = RNEA.snoc;
|
|
2239
|
+
/**
|
|
2240
|
+
* Use [`prependAll`](#prependall) instead.
|
|
2241
|
+
*
|
|
2242
|
+
* @category combinators
|
|
2243
|
+
* @since 2.9.0
|
|
2244
|
+
* @deprecated
|
|
2245
|
+
*/
|
|
2246
|
+
exports.prependToAll = exports.prependAll;
|
|
2247
|
+
/**
|
|
2248
|
+
* This instance is deprecated, use small, specific instances instead.
|
|
2249
|
+
* For example if a function needs a `Functor` instance, pass `RA.Functor` instead of `RA.readonlyArray`
|
|
2250
|
+
* (where `RA` is from `import RA from 'fp-ts/ReadonlyArray'`)
|
|
2251
|
+
*
|
|
2252
|
+
* @category instances
|
|
2253
|
+
* @since 2.5.0
|
|
2254
|
+
* @deprecated
|
|
2255
|
+
*/
|
|
2256
|
+
exports.readonlyArray = {
|
|
2257
|
+
URI: exports.URI,
|
|
2258
|
+
compact: exports.compact,
|
|
2259
|
+
separate: exports.separate,
|
|
2260
|
+
map: _map,
|
|
2261
|
+
ap: _ap,
|
|
2262
|
+
of: exports.of,
|
|
2263
|
+
chain: _chain,
|
|
2264
|
+
filter: _filter,
|
|
2265
|
+
filterMap: _filterMap,
|
|
2266
|
+
partition: _partition,
|
|
2267
|
+
partitionMap: _partitionMap,
|
|
2268
|
+
mapWithIndex: _mapWithIndex,
|
|
2269
|
+
partitionMapWithIndex: _partitionMapWithIndex,
|
|
2270
|
+
partitionWithIndex: _partitionWithIndex,
|
|
2271
|
+
filterMapWithIndex: _filterMapWithIndex,
|
|
2272
|
+
filterWithIndex: _filterWithIndex,
|
|
2273
|
+
alt: _alt,
|
|
2274
|
+
zero: exports.zero,
|
|
2275
|
+
unfold: exports.unfold,
|
|
2276
|
+
reduce: _reduce,
|
|
2277
|
+
foldMap: _foldMap,
|
|
2278
|
+
reduceRight: _reduceRight,
|
|
2279
|
+
traverse: _traverse,
|
|
2280
|
+
sequence: exports.sequence,
|
|
2281
|
+
reduceWithIndex: _reduceWithIndex,
|
|
2282
|
+
foldMapWithIndex: _foldMapWithIndex,
|
|
2283
|
+
reduceRightWithIndex: _reduceRightWithIndex,
|
|
2284
|
+
traverseWithIndex: _traverseWithIndex,
|
|
2285
|
+
extend: _extend,
|
|
2286
|
+
wither: _wither,
|
|
2287
|
+
wilt: _wilt
|
|
2288
|
+
};
|
|
2289
|
+
});
|
|
2290
|
+
|
|
2291
|
+
const ReadonlyArray$1 = /*@__PURE__*/getDefaultExportFromCjs(ReadonlyArray);
|
|
2292
|
+
|
|
2293
|
+
var _Array = createCommonjsModule(function (module, exports) {
|
|
2294
|
+
"use strict";
|
|
2295
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2296
|
+
if (k2 === undefined) k2 = k;
|
|
2297
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2298
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2299
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
2300
|
+
}
|
|
2301
|
+
Object.defineProperty(o, k2, desc);
|
|
2302
|
+
}) : (function(o, m, k, k2) {
|
|
2303
|
+
if (k2 === undefined) k2 = k;
|
|
2304
|
+
o[k2] = m[k];
|
|
2305
|
+
}));
|
|
2306
|
+
var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
2307
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
2308
|
+
}) : function(o, v) {
|
|
2309
|
+
o["default"] = v;
|
|
2310
|
+
});
|
|
2311
|
+
var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
|
|
2312
|
+
if (mod && mod.__esModule) return mod;
|
|
2313
|
+
var result = {};
|
|
2314
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
2315
|
+
__setModuleDefault(result, mod);
|
|
2316
|
+
return result;
|
|
2317
|
+
};
|
|
2318
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2319
|
+
exports.lefts = exports.rights = exports.reverse = exports.modifyAt = exports.deleteAt = exports.updateAt = exports.insertAt = exports.copy = exports.findLastIndex = exports.findLastMap = exports.findLast = exports.findFirstMap = exports.findFirst = exports.findIndex = exports.dropLeftWhile = exports.dropRight = exports.dropLeft = exports.spanLeft = exports.takeLeftWhile = exports.takeRight = exports.takeLeft = exports.init = exports.tail = exports.last = exports.head = exports.lookup = exports.isOutOfBound = exports.size = exports.scanRight = exports.scanLeft = exports.chainWithIndex = exports.foldRight = exports.matchRight = exports.matchRightW = exports.foldLeft = exports.matchLeft = exports.matchLeftW = exports.match = exports.matchW = exports.fromEither = exports.fromOption = exports.fromPredicate = exports.replicate = exports.makeBy = exports.appendW = exports.append = exports.prependW = exports.prepend = exports.isNonEmpty = exports.isEmpty = void 0;
|
|
2320
|
+
exports.traverseWithIndex = exports.sequence = exports.traverse = exports.reduceRightWithIndex = exports.reduceRight = exports.reduceWithIndex = exports.reduce = exports.foldMapWithIndex = exports.foldMap = exports.duplicate = exports.extend = exports.filterWithIndex = exports.alt = exports.altW = exports.partitionMapWithIndex = exports.partitionMap = exports.partitionWithIndex = exports.partition = exports.filter = exports.separate = exports.compact = exports.filterMap = exports.filterMapWithIndex = exports.mapWithIndex = exports.flatten = exports.chain = exports.ap = exports.map = exports.zero = exports.of = exports.difference = exports.intersection = exports.union = exports.concat = exports.concatW = exports.comprehension = exports.fromOptionK = exports.chunksOf = exports.splitAt = exports.chop = exports.sortBy = exports.uniq = exports.elem = exports.rotate = exports.intersperse = exports.prependAll = exports.unzip = exports.zip = exports.zipWith = exports.sort = void 0;
|
|
2321
|
+
exports.some = exports.every = exports.unsafeDeleteAt = exports.unsafeUpdateAt = exports.unsafeInsertAt = exports.fromEitherK = exports.FromEither = exports.filterE = exports.ChainRecBreadthFirst = exports.chainRecBreadthFirst = exports.ChainRecDepthFirst = exports.chainRecDepthFirst = exports.Witherable = exports.TraversableWithIndex = exports.Traversable = exports.FoldableWithIndex = exports.Foldable = exports.FilterableWithIndex = exports.Filterable = exports.Compactable = exports.Extend = exports.Alternative = exports.guard = exports.Zero = exports.Alt = exports.Unfoldable = exports.Monad = exports.chainFirst = exports.Chain = exports.Applicative = exports.apSecond = exports.apFirst = exports.Apply = exports.FunctorWithIndex = exports.Pointed = exports.flap = exports.Functor = exports.getDifferenceMagma = exports.getIntersectionSemigroup = exports.getUnionMonoid = exports.getUnionSemigroup = exports.getOrd = exports.getEq = exports.getMonoid = exports.getSemigroup = exports.getShow = exports.URI = exports.unfold = exports.wilt = exports.wither = void 0;
|
|
2322
|
+
exports.array = exports.prependToAll = exports.snoc = exports.cons = exports.empty = exports.range = exports.apS = exports.bind = exports.bindTo = exports.Do = exports.intercalate = exports.exists = void 0;
|
|
2323
|
+
|
|
2324
|
+
|
|
2325
|
+
|
|
2326
|
+
|
|
2327
|
+
|
|
2328
|
+
var _ = __importStar(internal);
|
|
2329
|
+
var NEA = __importStar(NonEmptyArray);
|
|
2330
|
+
var RA = __importStar(ReadonlyArray);
|
|
2331
|
+
|
|
2332
|
+
|
|
2333
|
+
|
|
2334
|
+
// -------------------------------------------------------------------------------------
|
|
2335
|
+
// refinements
|
|
2336
|
+
// -------------------------------------------------------------------------------------
|
|
2337
|
+
/**
|
|
2338
|
+
* Test whether an array is empty
|
|
2339
|
+
*
|
|
2340
|
+
* @example
|
|
2341
|
+
* import { isEmpty } from 'fp-ts/Array'
|
|
2342
|
+
*
|
|
2343
|
+
* assert.strictEqual(isEmpty([]), true)
|
|
2344
|
+
* assert.strictEqual(isEmpty(['a']), false)
|
|
2345
|
+
*
|
|
2346
|
+
* @category refinements
|
|
2347
|
+
* @since 2.0.0
|
|
2348
|
+
*/
|
|
2349
|
+
var isEmpty = function (as) { return as.length === 0; };
|
|
2350
|
+
exports.isEmpty = isEmpty;
|
|
2351
|
+
/**
|
|
2352
|
+
* Test whether an array is non empty narrowing down the type to `NonEmptyArray<A>`
|
|
2353
|
+
*
|
|
2354
|
+
* @example
|
|
2355
|
+
* import { isNonEmpty } from 'fp-ts/Array'
|
|
2356
|
+
*
|
|
2357
|
+
* assert.strictEqual(isNonEmpty([]), false)
|
|
2358
|
+
* assert.strictEqual(isNonEmpty(['a']), true)
|
|
2359
|
+
*
|
|
2360
|
+
* @category refinements
|
|
2361
|
+
* @since 2.0.0
|
|
2362
|
+
*/
|
|
2363
|
+
exports.isNonEmpty = NEA.isNonEmpty;
|
|
2364
|
+
// -------------------------------------------------------------------------------------
|
|
2365
|
+
// constructors
|
|
2366
|
+
// -------------------------------------------------------------------------------------
|
|
2367
|
+
/**
|
|
2368
|
+
* Prepend an element to the front of a `Array`, creating a new `NonEmptyArray`.
|
|
2369
|
+
*
|
|
2370
|
+
* @example
|
|
2371
|
+
* import { prepend } from 'fp-ts/Array'
|
|
2372
|
+
* import { pipe } from 'fp-ts/function'
|
|
2373
|
+
*
|
|
2374
|
+
* assert.deepStrictEqual(pipe([2, 3, 4], prepend(1)), [1, 2, 3, 4])
|
|
2375
|
+
*
|
|
2376
|
+
* @category constructors
|
|
2377
|
+
* @since 2.10.0
|
|
2378
|
+
*/
|
|
2379
|
+
exports.prepend = NEA.prepend;
|
|
2380
|
+
/**
|
|
2381
|
+
* Less strict version of [`prepend`](#prepend).
|
|
2382
|
+
*
|
|
2383
|
+
* @example
|
|
2384
|
+
* import { prependW } from 'fp-ts/Array'
|
|
2385
|
+
* import { pipe } from 'fp-ts/function'
|
|
2386
|
+
*
|
|
2387
|
+
* assert.deepStrictEqual(pipe([2, 3, 4], prependW("a")), ["a", 2, 3, 4]);
|
|
2388
|
+
*
|
|
2389
|
+
* @category constructors
|
|
2390
|
+
* @since 2.11.0
|
|
2391
|
+
*/
|
|
2392
|
+
exports.prependW = NEA.prependW;
|
|
2393
|
+
/**
|
|
2394
|
+
* Append an element to the end of a `Array`, creating a new `NonEmptyArray`.
|
|
2395
|
+
*
|
|
2396
|
+
* @example
|
|
2397
|
+
* import { append } from 'fp-ts/Array'
|
|
2398
|
+
* import { pipe } from 'fp-ts/function'
|
|
2399
|
+
*
|
|
2400
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], append(4)), [1, 2, 3, 4])
|
|
2401
|
+
*
|
|
2402
|
+
* @category constructors
|
|
2403
|
+
* @since 2.10.0
|
|
2404
|
+
*/
|
|
2405
|
+
exports.append = NEA.append;
|
|
2406
|
+
/**
|
|
2407
|
+
* Less strict version of [`append`](#append).
|
|
2408
|
+
*
|
|
2409
|
+
* @example
|
|
2410
|
+
* import { appendW } from 'fp-ts/Array'
|
|
2411
|
+
* import { pipe } from 'fp-ts/function'
|
|
2412
|
+
*
|
|
2413
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], appendW("d")), [1, 2, 3, "d"]);
|
|
2414
|
+
*
|
|
2415
|
+
* @category constructors
|
|
2416
|
+
* @since 2.11.0
|
|
2417
|
+
*/
|
|
2418
|
+
exports.appendW = NEA.appendW;
|
|
2419
|
+
/**
|
|
2420
|
+
* Return a `Array` of length `n` with element `i` initialized with `f(i)`.
|
|
2421
|
+
*
|
|
2422
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
2423
|
+
*
|
|
2424
|
+
* @example
|
|
2425
|
+
* import { makeBy } from 'fp-ts/Array'
|
|
2426
|
+
*
|
|
2427
|
+
* const double = (i: number): number => i * 2
|
|
2428
|
+
* assert.deepStrictEqual(makeBy(5, double), [0, 2, 4, 6, 8])
|
|
2429
|
+
* assert.deepStrictEqual(makeBy(-3, double), [])
|
|
2430
|
+
* assert.deepStrictEqual(makeBy(4.32164, double), [0, 2, 4, 6])
|
|
2431
|
+
*
|
|
2432
|
+
* @category constructors
|
|
2433
|
+
* @since 2.0.0
|
|
2434
|
+
*/
|
|
2435
|
+
var makeBy = function (n, f) { return (n <= 0 ? [] : NEA.makeBy(f)(n)); };
|
|
2436
|
+
exports.makeBy = makeBy;
|
|
2437
|
+
/**
|
|
2438
|
+
* Create a `Array` containing a value repeated the specified number of times.
|
|
2439
|
+
*
|
|
2440
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
2441
|
+
*
|
|
2442
|
+
* @example
|
|
2443
|
+
* import { replicate } from 'fp-ts/Array'
|
|
2444
|
+
*
|
|
2445
|
+
* assert.deepStrictEqual(replicate(3, 'a'), ['a', 'a', 'a'])
|
|
2446
|
+
* assert.deepStrictEqual(replicate(-3, 'a'), [])
|
|
2447
|
+
* assert.deepStrictEqual(replicate(2.985647, 'a'), ['a', 'a'])
|
|
2448
|
+
*
|
|
2449
|
+
* @category constructors
|
|
2450
|
+
* @since 2.0.0
|
|
2451
|
+
*/
|
|
2452
|
+
var replicate = function (n, a) { return (0, exports.makeBy)(n, function () { return a; }); };
|
|
2453
|
+
exports.replicate = replicate;
|
|
2454
|
+
function fromPredicate(predicate) {
|
|
2455
|
+
return function (a) { return (predicate(a) ? [a] : []); };
|
|
2456
|
+
}
|
|
2457
|
+
exports.fromPredicate = fromPredicate;
|
|
2458
|
+
// -------------------------------------------------------------------------------------
|
|
2459
|
+
// natural transformations
|
|
2460
|
+
// -------------------------------------------------------------------------------------
|
|
2461
|
+
/**
|
|
2462
|
+
* Create an array from an `Option`. The resulting array will contain the content of the
|
|
2463
|
+
* `Option` if it is `Some` and it will be empty if the `Option` is `None`.
|
|
2464
|
+
*
|
|
2465
|
+
* @example
|
|
2466
|
+
* import { fromOption } from 'fp-ts/Array'
|
|
2467
|
+
* import { option } from "fp-ts";
|
|
2468
|
+
* import { pipe } from 'fp-ts/function'
|
|
2469
|
+
*
|
|
2470
|
+
* assert.deepStrictEqual(pipe(option.some("a"), fromOption),["a"])
|
|
2471
|
+
* assert.deepStrictEqual(pipe(option.none, fromOption),[])
|
|
2472
|
+
*
|
|
2473
|
+
* @category natural transformations
|
|
2474
|
+
* @since 2.11.0
|
|
2475
|
+
*/
|
|
2476
|
+
var fromOption = function (ma) { return (_.isNone(ma) ? [] : [ma.value]); };
|
|
2477
|
+
exports.fromOption = fromOption;
|
|
2478
|
+
/**
|
|
2479
|
+
* Create an array from an `Either`. The resulting array will contain the content of the
|
|
2480
|
+
* `Either` if it is `Right` and it will be empty if the `Either` is `Left`.
|
|
2481
|
+
*
|
|
2482
|
+
* @example
|
|
2483
|
+
* import { fromEither } from 'fp-ts/Array'
|
|
2484
|
+
* import { either } from "fp-ts";
|
|
2485
|
+
* import { pipe } from 'fp-ts/function'
|
|
2486
|
+
*
|
|
2487
|
+
* assert.deepStrictEqual(pipe(either.right("r"), fromEither), ["r"]);
|
|
2488
|
+
* assert.deepStrictEqual(pipe(either.left("l"), fromEither), []);
|
|
2489
|
+
*
|
|
2490
|
+
* @category natural transformations
|
|
2491
|
+
* @since 2.11.0
|
|
2492
|
+
*/
|
|
2493
|
+
var fromEither = function (e) { return (_.isLeft(e) ? [] : [e.right]); };
|
|
2494
|
+
exports.fromEither = fromEither;
|
|
2495
|
+
// -------------------------------------------------------------------------------------
|
|
2496
|
+
// destructors
|
|
2497
|
+
// -------------------------------------------------------------------------------------
|
|
2498
|
+
/**
|
|
2499
|
+
* Less strict version of [`match`](#match). It will work when `onEmpty` and `onNonEmpty`
|
|
2500
|
+
* have different return types.
|
|
2501
|
+
*
|
|
2502
|
+
* @example
|
|
2503
|
+
* import { matchW } from 'fp-ts/Array'
|
|
2504
|
+
* import { pipe } from 'fp-ts/function'
|
|
2505
|
+
*
|
|
2506
|
+
* const matcherW = matchW(
|
|
2507
|
+
* () => "No elements",
|
|
2508
|
+
* (as) => as.length
|
|
2509
|
+
* );
|
|
2510
|
+
* assert.deepStrictEqual(pipe([1, 2, 3, 4], matcherW), 4);
|
|
2511
|
+
* assert.deepStrictEqual(pipe([], matcherW), "No elements");
|
|
2512
|
+
*
|
|
2513
|
+
* @category destructors
|
|
2514
|
+
* @since 2.11.0
|
|
2515
|
+
*/
|
|
2516
|
+
var matchW = function (onEmpty, onNonEmpty) { return function (as) {
|
|
2517
|
+
return (0, exports.isNonEmpty)(as) ? onNonEmpty(as) : onEmpty();
|
|
2518
|
+
}; };
|
|
2519
|
+
exports.matchW = matchW;
|
|
2520
|
+
/**
|
|
2521
|
+
* Takes an array, if the array is empty it returns the result of `onEmpty`, otherwise
|
|
2522
|
+
* it passes the array to `onNonEmpty` and returns the result.
|
|
2523
|
+
*
|
|
2524
|
+
* @example
|
|
2525
|
+
* import { match } from 'fp-ts/Array'
|
|
2526
|
+
* import { pipe } from 'fp-ts/function'
|
|
2527
|
+
*
|
|
2528
|
+
* const matcher = match(
|
|
2529
|
+
* () => "No elements",
|
|
2530
|
+
* (as) => `Found ${as.length} element(s)`
|
|
2531
|
+
* );
|
|
2532
|
+
* assert.deepStrictEqual(pipe([1, 2, 3, 4], matcher), "Found 4 element(s)");
|
|
2533
|
+
* assert.deepStrictEqual(pipe([], matcher), "No elements");
|
|
2534
|
+
*
|
|
2535
|
+
* @category destructors
|
|
2536
|
+
* @since 2.11.0
|
|
2537
|
+
*/
|
|
2538
|
+
exports.match = exports.matchW;
|
|
2539
|
+
/**
|
|
2540
|
+
* Less strict version of [`matchLeft`](#matchleft). It will work when `onEmpty` and
|
|
2541
|
+
* `onNonEmpty` have different return types.
|
|
2542
|
+
*
|
|
2543
|
+
* @example
|
|
2544
|
+
* import { matchLeftW } from 'fp-ts/Array'
|
|
2545
|
+
*
|
|
2546
|
+
* const f = matchLeftW(
|
|
2547
|
+
* () => 0,
|
|
2548
|
+
* (head: string, tail: string[]) => `Found "${head}" followed by ${tail.length} elements`
|
|
2549
|
+
* );
|
|
2550
|
+
* assert.strictEqual(f(["a", "b", "c"]), 'Found "a" followed by 2 elements');
|
|
2551
|
+
* assert.strictEqual(f([]), 0);
|
|
2552
|
+
*
|
|
2553
|
+
* @category destructors
|
|
2554
|
+
* @since 2.11.0
|
|
2555
|
+
*/
|
|
2556
|
+
var matchLeftW = function (onEmpty, onNonEmpty) { return function (as) { return ((0, exports.isNonEmpty)(as) ? onNonEmpty(NEA.head(as), NEA.tail(as)) : onEmpty()); }; };
|
|
2557
|
+
exports.matchLeftW = matchLeftW;
|
|
2558
|
+
/**
|
|
2559
|
+
* Takes an array, if the array is empty it returns the result of `onEmpty`, otherwise
|
|
2560
|
+
* it passes the array to `onNonEmpty` broken into its first element and remaining elements.
|
|
2561
|
+
*
|
|
2562
|
+
* @example
|
|
2563
|
+
* import { matchLeft } from 'fp-ts/Array'
|
|
2564
|
+
*
|
|
2565
|
+
* const len: <A>(as: Array<A>) => number = matchLeft(() => 0, (_, tail) => 1 + len(tail))
|
|
2566
|
+
* assert.strictEqual(len([1, 2, 3]), 3)
|
|
2567
|
+
*
|
|
2568
|
+
* @category destructors
|
|
2569
|
+
* @since 2.10.0
|
|
2570
|
+
*/
|
|
2571
|
+
exports.matchLeft = exports.matchLeftW;
|
|
2572
|
+
/**
|
|
2573
|
+
* Alias of [`matchLeft`](#matchleft).
|
|
2574
|
+
*
|
|
2575
|
+
* @category destructors
|
|
2576
|
+
* @since 2.0.0
|
|
2577
|
+
*/
|
|
2578
|
+
exports.foldLeft = exports.matchLeft;
|
|
2579
|
+
/**
|
|
2580
|
+
* Less strict version of [`matchRight`](#matchright). It will work when `onEmpty` and
|
|
2581
|
+
* `onNonEmpty` have different return types.
|
|
2582
|
+
*
|
|
2583
|
+
* @example
|
|
2584
|
+
* import { matchRightW } from 'fp-ts/Array'
|
|
2585
|
+
*
|
|
2586
|
+
* const f = matchRightW(
|
|
2587
|
+
* () => 0,
|
|
2588
|
+
* (head: string[], tail: string) => `Found ${head.length} elements folllowed by "${tail}"`
|
|
2589
|
+
* );
|
|
2590
|
+
* assert.strictEqual(f(["a", "b", "c"]), 'Found 2 elements folllowed by "c"');
|
|
2591
|
+
* assert.strictEqual(f([]), 0);
|
|
2592
|
+
*
|
|
2593
|
+
* @category destructors
|
|
2594
|
+
* @since 2.11.0
|
|
2595
|
+
*/
|
|
2596
|
+
var matchRightW = function (onEmpty, onNonEmpty) { return function (as) { return ((0, exports.isNonEmpty)(as) ? onNonEmpty(NEA.init(as), NEA.last(as)) : onEmpty()); }; };
|
|
2597
|
+
exports.matchRightW = matchRightW;
|
|
2598
|
+
/**
|
|
2599
|
+
* Takes an array, if the array is empty it returns the result of `onEmpty`, otherwise
|
|
2600
|
+
* it passes the array to `onNonEmpty` broken into its initial elements and the last element.
|
|
2601
|
+
*
|
|
2602
|
+
* @example
|
|
2603
|
+
* import { matchRight } from 'fp-ts/Array'
|
|
2604
|
+
*
|
|
2605
|
+
* const len: <A>(as: Array<A>) => number = matchRight(
|
|
2606
|
+
* () => 0,
|
|
2607
|
+
* (head, _) => 1 + len(head)
|
|
2608
|
+
* );
|
|
2609
|
+
* assert.strictEqual(len([1, 2, 3]), 3);
|
|
2610
|
+
*
|
|
2611
|
+
* @category destructors
|
|
2612
|
+
* @since 2.10.0
|
|
2613
|
+
*/
|
|
2614
|
+
exports.matchRight = exports.matchRightW;
|
|
2615
|
+
/**
|
|
2616
|
+
* Alias of [`matchRight`](#matchright).
|
|
2617
|
+
*
|
|
2618
|
+
* @category destructors
|
|
2619
|
+
* @since 2.0.0
|
|
2620
|
+
*/
|
|
2621
|
+
exports.foldRight = exports.matchRight;
|
|
2622
|
+
// -------------------------------------------------------------------------------------
|
|
2623
|
+
// combinators
|
|
2624
|
+
// -------------------------------------------------------------------------------------
|
|
2625
|
+
/**
|
|
2626
|
+
* Same as [`chain`](#chain), but passing also the index to the iterating function.
|
|
2627
|
+
*
|
|
2628
|
+
* @example
|
|
2629
|
+
* import { chainWithIndex, replicate } from 'fp-ts/Array'
|
|
2630
|
+
* import { pipe } from 'fp-ts/function'
|
|
2631
|
+
*
|
|
2632
|
+
* const f = (index: number, x: string) => replicate(2, `${x}${index}`);
|
|
2633
|
+
* assert.deepStrictEqual(pipe(["a", "b", "c"], chainWithIndex(f)), ["a0", "a0", "b1", "b1", "c2", "c2"]);
|
|
2634
|
+
*
|
|
2635
|
+
* @category combinators
|
|
2636
|
+
* @since 2.7.0
|
|
2637
|
+
*/
|
|
2638
|
+
var chainWithIndex = function (f) { return function (as) {
|
|
2639
|
+
var out = [];
|
|
2640
|
+
for (var i = 0; i < as.length; i++) {
|
|
2641
|
+
out.push.apply(out, f(i, as[i]));
|
|
2642
|
+
}
|
|
2643
|
+
return out;
|
|
2644
|
+
}; };
|
|
2645
|
+
exports.chainWithIndex = chainWithIndex;
|
|
2646
|
+
/**
|
|
2647
|
+
* Same as `reduce` but it carries over the intermediate steps
|
|
2648
|
+
*
|
|
2649
|
+
* @example
|
|
2650
|
+
* import { scanLeft } from 'fp-ts/Array'
|
|
2651
|
+
*
|
|
2652
|
+
* assert.deepStrictEqual(scanLeft(10, (b, a: number) => b - a)([1, 2, 3]), [10, 9, 7, 4])
|
|
2653
|
+
*
|
|
2654
|
+
* @category combinators
|
|
2655
|
+
* @since 2.0.0
|
|
2656
|
+
*/
|
|
2657
|
+
var scanLeft = function (b, f) { return function (as) {
|
|
2658
|
+
var len = as.length;
|
|
2659
|
+
var out = new Array(len + 1);
|
|
2660
|
+
out[0] = b;
|
|
2661
|
+
for (var i = 0; i < len; i++) {
|
|
2662
|
+
out[i + 1] = f(out[i], as[i]);
|
|
2663
|
+
}
|
|
2664
|
+
return out;
|
|
2665
|
+
}; };
|
|
2666
|
+
exports.scanLeft = scanLeft;
|
|
2667
|
+
/**
|
|
2668
|
+
* Fold an array from the right, keeping all intermediate results instead of only the final result
|
|
2669
|
+
*
|
|
2670
|
+
* @example
|
|
2671
|
+
* import { scanRight } from 'fp-ts/Array'
|
|
2672
|
+
*
|
|
2673
|
+
* assert.deepStrictEqual(scanRight(10, (a: number, b) => b - a)([1, 2, 3]), [4, 5, 7, 10])
|
|
2674
|
+
*
|
|
2675
|
+
* @category combinators
|
|
2676
|
+
* @since 2.0.0
|
|
2677
|
+
*/
|
|
2678
|
+
var scanRight = function (b, f) { return function (as) {
|
|
2679
|
+
var len = as.length;
|
|
2680
|
+
var out = new Array(len + 1);
|
|
2681
|
+
out[len] = b;
|
|
2682
|
+
for (var i = len - 1; i >= 0; i--) {
|
|
2683
|
+
out[i] = f(as[i], out[i + 1]);
|
|
2684
|
+
}
|
|
2685
|
+
return out;
|
|
2686
|
+
}; };
|
|
2687
|
+
exports.scanRight = scanRight;
|
|
2688
|
+
/**
|
|
2689
|
+
* Calculate the number of elements in a `Array`.
|
|
2690
|
+
*
|
|
2691
|
+
* @example
|
|
2692
|
+
* import { size } from 'fp-ts/Array'
|
|
2693
|
+
*
|
|
2694
|
+
* assert.strictEqual(size(["a","b","c"]),3)
|
|
2695
|
+
*
|
|
2696
|
+
* @since 2.10.0
|
|
2697
|
+
*/
|
|
2698
|
+
var size = function (as) { return as.length; };
|
|
2699
|
+
exports.size = size;
|
|
2700
|
+
/**
|
|
2701
|
+
* Test whether an array contains a particular index
|
|
2702
|
+
*
|
|
2703
|
+
* @example
|
|
2704
|
+
* import { isOutOfBound } from 'fp-ts/Array'
|
|
2705
|
+
*
|
|
2706
|
+
* assert.strictEqual(isOutOfBound(1,["a","b","c"]),false)
|
|
2707
|
+
* assert.strictEqual(isOutOfBound(-1,["a","b","c"]),true)
|
|
2708
|
+
* assert.strictEqual(isOutOfBound(3,["a","b","c"]),true)
|
|
2709
|
+
*
|
|
2710
|
+
* @since 2.0.0
|
|
2711
|
+
*/
|
|
2712
|
+
exports.isOutOfBound = NEA.isOutOfBound;
|
|
2713
|
+
// TODO: remove non-curried overloading in v3
|
|
2714
|
+
/**
|
|
2715
|
+
* This function provides a safe way to read a value at a particular index from an array.
|
|
2716
|
+
* It returns a `none` if the index is out of bounds, and a `some` of the element if the
|
|
2717
|
+
* index is valid.
|
|
2718
|
+
*
|
|
2719
|
+
* @example
|
|
2720
|
+
* import { lookup } from 'fp-ts/Array'
|
|
2721
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2722
|
+
* import { pipe } from 'fp-ts/function'
|
|
2723
|
+
*
|
|
2724
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], lookup(1)), some(2))
|
|
2725
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], lookup(3)), none)
|
|
2726
|
+
*
|
|
2727
|
+
* @since 2.0.0
|
|
2728
|
+
*/
|
|
2729
|
+
exports.lookup = RA.lookup;
|
|
2730
|
+
/**
|
|
2731
|
+
* Get the first element in an array, or `None` if the array is empty
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* import { head } from 'fp-ts/Array'
|
|
2735
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2736
|
+
*
|
|
2737
|
+
* assert.deepStrictEqual(head([1, 2, 3]), some(1))
|
|
2738
|
+
* assert.deepStrictEqual(head([]), none)
|
|
2739
|
+
*
|
|
2740
|
+
* @category destructors
|
|
2741
|
+
* @since 2.0.0
|
|
2742
|
+
*/
|
|
2743
|
+
exports.head = RA.head;
|
|
2744
|
+
/**
|
|
2745
|
+
* Get the last element in an array, or `None` if the array is empty
|
|
2746
|
+
*
|
|
2747
|
+
* @example
|
|
2748
|
+
* import { last } from 'fp-ts/Array'
|
|
2749
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2750
|
+
*
|
|
2751
|
+
* assert.deepStrictEqual(last([1, 2, 3]), some(3))
|
|
2752
|
+
* assert.deepStrictEqual(last([]), none)
|
|
2753
|
+
*
|
|
2754
|
+
* @category destructors
|
|
2755
|
+
* @since 2.0.0
|
|
2756
|
+
*/
|
|
2757
|
+
exports.last = RA.last;
|
|
2758
|
+
/**
|
|
2759
|
+
* Get all but the first element of an array, creating a new array, or `None` if the array is empty
|
|
2760
|
+
*
|
|
2761
|
+
* @example
|
|
2762
|
+
* import { tail } from 'fp-ts/Array'
|
|
2763
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2764
|
+
*
|
|
2765
|
+
* assert.deepStrictEqual(tail([1, 2, 3]), some([2, 3]))
|
|
2766
|
+
* assert.deepStrictEqual(tail([]), none)
|
|
2767
|
+
*
|
|
2768
|
+
* @category destructors
|
|
2769
|
+
* @since 2.0.0
|
|
2770
|
+
*/
|
|
2771
|
+
var tail = function (as) { return ((0, exports.isNonEmpty)(as) ? _.some(NEA.tail(as)) : _.none); };
|
|
2772
|
+
exports.tail = tail;
|
|
2773
|
+
/**
|
|
2774
|
+
* Get all but the last element of an array, creating a new array, or `None` if the array is empty
|
|
2775
|
+
*
|
|
2776
|
+
* @example
|
|
2777
|
+
* import { init } from 'fp-ts/Array'
|
|
2778
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2779
|
+
*
|
|
2780
|
+
* assert.deepStrictEqual(init([1, 2, 3]), some([1, 2]))
|
|
2781
|
+
* assert.deepStrictEqual(init([]), none)
|
|
2782
|
+
*
|
|
2783
|
+
* @category destructors
|
|
2784
|
+
* @since 2.0.0
|
|
2785
|
+
*/
|
|
2786
|
+
var init = function (as) { return ((0, exports.isNonEmpty)(as) ? _.some(NEA.init(as)) : _.none); };
|
|
2787
|
+
exports.init = init;
|
|
2788
|
+
/**
|
|
2789
|
+
* Keep only a max number of elements from the start of an `Array`, creating a new `Array`.
|
|
2790
|
+
*
|
|
2791
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
2792
|
+
*
|
|
2793
|
+
* @example
|
|
2794
|
+
* import { takeLeft } from 'fp-ts/Array'
|
|
2795
|
+
*
|
|
2796
|
+
* assert.deepStrictEqual(takeLeft(2)([1, 2, 3, 4, 5]), [1, 2]);
|
|
2797
|
+
* assert.deepStrictEqual(takeLeft(7)([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]);
|
|
2798
|
+
* assert.deepStrictEqual(takeLeft(0)([1, 2, 3, 4, 5]), []);
|
|
2799
|
+
* assert.deepStrictEqual(takeLeft(-1)([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]);
|
|
2800
|
+
*
|
|
2801
|
+
* @category combinators
|
|
2802
|
+
* @since 2.0.0
|
|
2803
|
+
*/
|
|
2804
|
+
var takeLeft = function (n) { return function (as) { return ((0, exports.isOutOfBound)(n, as) ? (0, exports.copy)(as) : as.slice(0, n)); }; };
|
|
2805
|
+
exports.takeLeft = takeLeft;
|
|
2806
|
+
/**
|
|
2807
|
+
* Keep only a max number of elements from the end of an `Array`, creating a new `Array`.
|
|
2808
|
+
*
|
|
2809
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
2810
|
+
*
|
|
2811
|
+
* @example
|
|
2812
|
+
* import { takeRight } from 'fp-ts/Array'
|
|
2813
|
+
*
|
|
2814
|
+
* assert.deepStrictEqual(takeRight(2)([1, 2, 3, 4, 5]), [4, 5]);
|
|
2815
|
+
* assert.deepStrictEqual(takeRight(7)([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]);
|
|
2816
|
+
* assert.deepStrictEqual(takeRight(0)([1, 2, 3, 4, 5]), []);
|
|
2817
|
+
* assert.deepStrictEqual(takeRight(-1)([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]);
|
|
2818
|
+
*
|
|
2819
|
+
* @category combinators
|
|
2820
|
+
* @since 2.0.0
|
|
2821
|
+
*/
|
|
2822
|
+
var takeRight = function (n) { return function (as) {
|
|
2823
|
+
return (0, exports.isOutOfBound)(n, as) ? (0, exports.copy)(as) : n === 0 ? [] : as.slice(-n);
|
|
2824
|
+
}; };
|
|
2825
|
+
exports.takeRight = takeRight;
|
|
2826
|
+
function takeLeftWhile(predicate) {
|
|
2827
|
+
return function (as) {
|
|
2828
|
+
var out = [];
|
|
2829
|
+
for (var _i = 0, as_1 = as; _i < as_1.length; _i++) {
|
|
2830
|
+
var a = as_1[_i];
|
|
2831
|
+
if (!predicate(a)) {
|
|
2832
|
+
break;
|
|
2833
|
+
}
|
|
2834
|
+
out.push(a);
|
|
2835
|
+
}
|
|
2836
|
+
return out;
|
|
2837
|
+
};
|
|
2838
|
+
}
|
|
2839
|
+
exports.takeLeftWhile = takeLeftWhile;
|
|
2840
|
+
var spanLeftIndex = function (as, predicate) {
|
|
2841
|
+
var l = as.length;
|
|
2842
|
+
var i = 0;
|
|
2843
|
+
for (; i < l; i++) {
|
|
2844
|
+
if (!predicate(as[i])) {
|
|
2845
|
+
break;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
return i;
|
|
2849
|
+
};
|
|
2850
|
+
function spanLeft(predicate) {
|
|
2851
|
+
return function (as) {
|
|
2852
|
+
var _a = (0, exports.splitAt)(spanLeftIndex(as, predicate))(as), init = _a[0], rest = _a[1];
|
|
2853
|
+
return { init: init, rest: rest };
|
|
2854
|
+
};
|
|
2855
|
+
}
|
|
2856
|
+
exports.spanLeft = spanLeft;
|
|
2857
|
+
/**
|
|
2858
|
+
* Creates a new `Array` which is a copy of the input dropping a max number of elements from the start.
|
|
2859
|
+
*
|
|
2860
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
2861
|
+
*
|
|
2862
|
+
* @example
|
|
2863
|
+
* import { dropLeft } from 'fp-ts/Array'
|
|
2864
|
+
*
|
|
2865
|
+
* assert.deepStrictEqual(dropLeft(2)([1, 2, 3]), [3]);
|
|
2866
|
+
* assert.deepStrictEqual(dropLeft(5)([1, 2, 3]), []);
|
|
2867
|
+
* assert.deepStrictEqual(dropLeft(0)([1, 2, 3]), [1, 2, 3]);
|
|
2868
|
+
* assert.deepStrictEqual(dropLeft(-2)([1, 2, 3]), [1, 2, 3]);
|
|
2869
|
+
*
|
|
2870
|
+
* @category combinators
|
|
2871
|
+
* @since 2.0.0
|
|
2872
|
+
*/
|
|
2873
|
+
var dropLeft = function (n) { return function (as) {
|
|
2874
|
+
return n <= 0 || (0, exports.isEmpty)(as) ? (0, exports.copy)(as) : n >= as.length ? [] : as.slice(n, as.length);
|
|
2875
|
+
}; };
|
|
2876
|
+
exports.dropLeft = dropLeft;
|
|
2877
|
+
/**
|
|
2878
|
+
* Creates a new `Array` which is a copy of the input dropping a max number of elements from the end.
|
|
2879
|
+
*
|
|
2880
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
2881
|
+
*
|
|
2882
|
+
* @example
|
|
2883
|
+
* import { dropRight } from 'fp-ts/Array'
|
|
2884
|
+
*
|
|
2885
|
+
* assert.deepStrictEqual(dropRight(2)([1, 2, 3]), [1]);
|
|
2886
|
+
* assert.deepStrictEqual(dropRight(5)([1, 2, 3]), []);
|
|
2887
|
+
* assert.deepStrictEqual(dropRight(0)([1, 2, 3]), [1, 2, 3]);
|
|
2888
|
+
* assert.deepStrictEqual(dropRight(-2)([1, 2, 3]), [1, 2, 3]);
|
|
2889
|
+
*
|
|
2890
|
+
* @category combinators
|
|
2891
|
+
* @since 2.0.0
|
|
2892
|
+
*/
|
|
2893
|
+
var dropRight = function (n) { return function (as) {
|
|
2894
|
+
return n <= 0 || (0, exports.isEmpty)(as) ? (0, exports.copy)(as) : n >= as.length ? [] : as.slice(0, as.length - n);
|
|
2895
|
+
}; };
|
|
2896
|
+
exports.dropRight = dropRight;
|
|
2897
|
+
function dropLeftWhile(predicate) {
|
|
2898
|
+
return function (as) { return as.slice(spanLeftIndex(as, predicate)); };
|
|
2899
|
+
}
|
|
2900
|
+
exports.dropLeftWhile = dropLeftWhile;
|
|
2901
|
+
/**
|
|
2902
|
+
* `findIndex` returns an `Option` containing the first index for which a predicate holds.
|
|
2903
|
+
* It returns `None` if no element satisfies the predicate.
|
|
2904
|
+
* Similar to [`findFirst`](#findFirst) but returning the index instead of the element.
|
|
2905
|
+
*
|
|
2906
|
+
* @example
|
|
2907
|
+
* import { findIndex } from 'fp-ts/Array'
|
|
2908
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2909
|
+
*
|
|
2910
|
+
* assert.deepStrictEqual(findIndex((n: number) => n === 2)([1, 2, 3]), some(1))
|
|
2911
|
+
* assert.deepStrictEqual(findIndex((n: number) => n === 2)([]), none)
|
|
2912
|
+
*
|
|
2913
|
+
* @since 2.0.0
|
|
2914
|
+
*/
|
|
2915
|
+
exports.findIndex = RA.findIndex;
|
|
2916
|
+
function findFirst(predicate) {
|
|
2917
|
+
return RA.findFirst(predicate);
|
|
2918
|
+
}
|
|
2919
|
+
exports.findFirst = findFirst;
|
|
2920
|
+
/**
|
|
2921
|
+
* Given a selector function which takes an element and returns an option,
|
|
2922
|
+
* this function applies the selector to each element of the array and
|
|
2923
|
+
* returns the first `Some` result. Otherwise it returns `None`.
|
|
2924
|
+
*
|
|
2925
|
+
* @example
|
|
2926
|
+
* import { findFirstMap } from 'fp-ts/Array'
|
|
2927
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2928
|
+
*
|
|
2929
|
+
* interface Person {
|
|
2930
|
+
* readonly name: string;
|
|
2931
|
+
* readonly age: number;
|
|
2932
|
+
* }
|
|
2933
|
+
*
|
|
2934
|
+
* const persons: Array<Person> = [
|
|
2935
|
+
* { name: "John", age: 16 },
|
|
2936
|
+
* { name: "Mary", age: 45 },
|
|
2937
|
+
* { name: "Joey", age: 28 },
|
|
2938
|
+
* ];
|
|
2939
|
+
*
|
|
2940
|
+
* const nameOfPersonAbove18 = (p: Person) => (p.age <= 18 ? none : some(p.name));
|
|
2941
|
+
* const nameOfPersonAbove70 = (p: Person) => (p.age <= 70 ? none : some(p.name));
|
|
2942
|
+
* assert.deepStrictEqual(findFirstMap(nameOfPersonAbove18)(persons), some("Mary"));
|
|
2943
|
+
* assert.deepStrictEqual(findFirstMap(nameOfPersonAbove70)(persons), none);
|
|
2944
|
+
*
|
|
2945
|
+
* @category destructors
|
|
2946
|
+
* @since 2.0.0
|
|
2947
|
+
*/
|
|
2948
|
+
exports.findFirstMap = RA.findFirstMap;
|
|
2949
|
+
function findLast(predicate) {
|
|
2950
|
+
return RA.findLast(predicate);
|
|
2951
|
+
}
|
|
2952
|
+
exports.findLast = findLast;
|
|
2953
|
+
/**
|
|
2954
|
+
* Given a selector function which takes an element and returns an option,
|
|
2955
|
+
* this function applies the selector to each element of the array starting from the
|
|
2956
|
+
* end and returns the last `Some` result. Otherwise it returns `None`.
|
|
2957
|
+
*
|
|
2958
|
+
* @example
|
|
2959
|
+
* import { findLastMap } from 'fp-ts/Array'
|
|
2960
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2961
|
+
*
|
|
2962
|
+
* interface Person {
|
|
2963
|
+
* readonly name: string;
|
|
2964
|
+
* readonly age: number;
|
|
2965
|
+
* }
|
|
2966
|
+
*
|
|
2967
|
+
* const persons: Array<Person> = [
|
|
2968
|
+
* { name: "John", age: 16 },
|
|
2969
|
+
* { name: "Mary", age: 45 },
|
|
2970
|
+
* { name: "Joey", age: 28 },
|
|
2971
|
+
* ];
|
|
2972
|
+
*
|
|
2973
|
+
* const nameOfPersonAbove18 = (p: Person) => (p.age <= 18 ? none : some(p.name));
|
|
2974
|
+
* const nameOfPersonAbove70 = (p: Person) => (p.age <= 70 ? none : some(p.name));
|
|
2975
|
+
* assert.deepStrictEqual(findLastMap(nameOfPersonAbove18)(persons), some("Joey"));
|
|
2976
|
+
* assert.deepStrictEqual(findLastMap(nameOfPersonAbove70)(persons), none);
|
|
2977
|
+
*
|
|
2978
|
+
* @category destructors
|
|
2979
|
+
* @since 2.0.0
|
|
2980
|
+
*/
|
|
2981
|
+
exports.findLastMap = RA.findLastMap;
|
|
2982
|
+
/**
|
|
2983
|
+
* Returns the index of the last element of the list which matches the predicate.
|
|
2984
|
+
* It returns an `Option` containing the index or `None` if not found.
|
|
2985
|
+
*
|
|
2986
|
+
* @example
|
|
2987
|
+
* import { findLastIndex } from 'fp-ts/Array'
|
|
2988
|
+
* import { some, none } from 'fp-ts/Option'
|
|
2989
|
+
*
|
|
2990
|
+
* interface X {
|
|
2991
|
+
* readonly a: number
|
|
2992
|
+
* readonly b: number
|
|
2993
|
+
* }
|
|
2994
|
+
* const xs: Array<X> = [{ a: 1, b: 0 }, { a: 1, b: 1 }]
|
|
2995
|
+
* assert.deepStrictEqual(findLastIndex((x: { readonly a: number }) => x.a === 1)(xs), some(1))
|
|
2996
|
+
* assert.deepStrictEqual(findLastIndex((x: { readonly a: number }) => x.a === 4)(xs), none)
|
|
2997
|
+
*
|
|
2998
|
+
* @since 2.0.0
|
|
2999
|
+
*/
|
|
3000
|
+
exports.findLastIndex = RA.findLastIndex;
|
|
3001
|
+
/**
|
|
3002
|
+
* This function takes an array and makes a new array containing the same elements.
|
|
3003
|
+
*
|
|
3004
|
+
* @category combinators
|
|
3005
|
+
* @since 2.0.0
|
|
3006
|
+
*/
|
|
3007
|
+
var copy = function (as) { return as.slice(); };
|
|
3008
|
+
exports.copy = copy;
|
|
3009
|
+
/**
|
|
3010
|
+
* Insert an element at the specified index, creating a new array,
|
|
3011
|
+
* or returning `None` if the index is out of bounds.
|
|
3012
|
+
*
|
|
3013
|
+
* @example
|
|
3014
|
+
* import { insertAt } from 'fp-ts/Array'
|
|
3015
|
+
* import { some } from 'fp-ts/Option'
|
|
3016
|
+
*
|
|
3017
|
+
* assert.deepStrictEqual(insertAt(2, 5)([1, 2, 3, 4]), some([1, 2, 5, 3, 4]))
|
|
3018
|
+
*
|
|
3019
|
+
* @since 2.0.0
|
|
3020
|
+
*/
|
|
3021
|
+
var insertAt = function (i, a) { return function (as) {
|
|
3022
|
+
return i < 0 || i > as.length ? _.none : _.some((0, exports.unsafeInsertAt)(i, a, as));
|
|
3023
|
+
}; };
|
|
3024
|
+
exports.insertAt = insertAt;
|
|
3025
|
+
/**
|
|
3026
|
+
* Change the element at the specified index, creating a new array,
|
|
3027
|
+
* or returning `None` if the index is out of bounds.
|
|
3028
|
+
*
|
|
3029
|
+
* @example
|
|
3030
|
+
* import { updateAt } from 'fp-ts/Array'
|
|
3031
|
+
* import { some, none } from 'fp-ts/Option'
|
|
3032
|
+
*
|
|
3033
|
+
* assert.deepStrictEqual(updateAt(1, 1)([1, 2, 3]), some([1, 1, 3]))
|
|
3034
|
+
* assert.deepStrictEqual(updateAt(1, 1)([]), none)
|
|
3035
|
+
*
|
|
3036
|
+
* @since 2.0.0
|
|
3037
|
+
*/
|
|
3038
|
+
var updateAt = function (i, a) { return (0, exports.modifyAt)(i, function () { return a; }); };
|
|
3039
|
+
exports.updateAt = updateAt;
|
|
3040
|
+
/**
|
|
3041
|
+
* Delete the element at the specified index, creating a new array, or returning `None` if the index is out of bounds.
|
|
3042
|
+
*
|
|
3043
|
+
* @example
|
|
3044
|
+
* import { deleteAt } from 'fp-ts/Array'
|
|
3045
|
+
* import { some, none } from 'fp-ts/Option'
|
|
3046
|
+
*
|
|
3047
|
+
* assert.deepStrictEqual(deleteAt(0)([1, 2, 3]), some([2, 3]))
|
|
3048
|
+
* assert.deepStrictEqual(deleteAt(1)([]), none)
|
|
3049
|
+
*
|
|
3050
|
+
* @since 2.0.0
|
|
3051
|
+
*/
|
|
3052
|
+
var deleteAt = function (i) { return function (as) {
|
|
3053
|
+
return (0, exports.isOutOfBound)(i, as) ? _.none : _.some((0, exports.unsafeDeleteAt)(i, as));
|
|
3054
|
+
}; };
|
|
3055
|
+
exports.deleteAt = deleteAt;
|
|
3056
|
+
/**
|
|
3057
|
+
* Apply a function to the element at the specified index, creating a new array, or returning `None` if the index is out
|
|
3058
|
+
* of bounds.
|
|
3059
|
+
*
|
|
3060
|
+
* @example
|
|
3061
|
+
* import { modifyAt } from 'fp-ts/Array'
|
|
3062
|
+
* import { some, none } from 'fp-ts/Option'
|
|
3063
|
+
*
|
|
3064
|
+
* const double = (x: number): number => x * 2
|
|
3065
|
+
* assert.deepStrictEqual(modifyAt(1, double)([1, 2, 3]), some([1, 4, 3]))
|
|
3066
|
+
* assert.deepStrictEqual(modifyAt(1, double)([]), none)
|
|
3067
|
+
*
|
|
3068
|
+
* @since 2.0.0
|
|
3069
|
+
*/
|
|
3070
|
+
var modifyAt = function (i, f) { return function (as) {
|
|
3071
|
+
return (0, exports.isOutOfBound)(i, as) ? _.none : _.some((0, exports.unsafeUpdateAt)(i, f(as[i]), as));
|
|
3072
|
+
}; };
|
|
3073
|
+
exports.modifyAt = modifyAt;
|
|
3074
|
+
/**
|
|
3075
|
+
* Reverse an array, creating a new array
|
|
3076
|
+
*
|
|
3077
|
+
* @example
|
|
3078
|
+
* import { reverse } from 'fp-ts/Array'
|
|
3079
|
+
*
|
|
3080
|
+
* assert.deepStrictEqual(reverse([1, 2, 3]), [3, 2, 1])
|
|
3081
|
+
*
|
|
3082
|
+
* @category combinators
|
|
3083
|
+
* @since 2.0.0
|
|
3084
|
+
*/
|
|
3085
|
+
var reverse = function (as) { return ((0, exports.isEmpty)(as) ? [] : as.slice().reverse()); };
|
|
3086
|
+
exports.reverse = reverse;
|
|
3087
|
+
/**
|
|
3088
|
+
* Takes an `Array` of `Either` and produces a new `Array` containing
|
|
3089
|
+
* the values of all the `Right` elements in the same order.
|
|
3090
|
+
*
|
|
3091
|
+
* @example
|
|
3092
|
+
* import { rights } from 'fp-ts/Array'
|
|
3093
|
+
* import { right, left } from 'fp-ts/Either'
|
|
3094
|
+
*
|
|
3095
|
+
* assert.deepStrictEqual(rights([right(1), left('foo'), right(2)]), [1, 2])
|
|
3096
|
+
*
|
|
3097
|
+
* @category combinators
|
|
3098
|
+
* @since 2.0.0
|
|
3099
|
+
*/
|
|
3100
|
+
var rights = function (as) {
|
|
3101
|
+
var r = [];
|
|
3102
|
+
for (var i = 0; i < as.length; i++) {
|
|
3103
|
+
var a = as[i];
|
|
3104
|
+
if (a._tag === 'Right') {
|
|
3105
|
+
r.push(a.right);
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
return r;
|
|
3109
|
+
};
|
|
3110
|
+
exports.rights = rights;
|
|
3111
|
+
/**
|
|
3112
|
+
* Takes an `Array` of `Either` and produces a new `Array` containing
|
|
3113
|
+
* the values of all the `Left` elements in the same order.
|
|
3114
|
+
*
|
|
3115
|
+
* @example
|
|
3116
|
+
* import { lefts } from 'fp-ts/Array'
|
|
3117
|
+
* import { left, right } from 'fp-ts/Either'
|
|
3118
|
+
*
|
|
3119
|
+
* assert.deepStrictEqual(lefts([right(1), left('foo'), right(2)]), ['foo'])
|
|
3120
|
+
*
|
|
3121
|
+
* @category combinators
|
|
3122
|
+
* @since 2.0.0
|
|
3123
|
+
*/
|
|
3124
|
+
var lefts = function (as) {
|
|
3125
|
+
var r = [];
|
|
3126
|
+
for (var i = 0; i < as.length; i++) {
|
|
3127
|
+
var a = as[i];
|
|
3128
|
+
if (a._tag === 'Left') {
|
|
3129
|
+
r.push(a.left);
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
return r;
|
|
3133
|
+
};
|
|
3134
|
+
exports.lefts = lefts;
|
|
3135
|
+
/**
|
|
3136
|
+
* Sort the elements of an array in increasing order, creating a new array
|
|
3137
|
+
*
|
|
3138
|
+
* @example
|
|
3139
|
+
* import { sort } from 'fp-ts/Array'
|
|
3140
|
+
* import * as N from 'fp-ts/number'
|
|
3141
|
+
*
|
|
3142
|
+
* assert.deepStrictEqual(sort(N.Ord)([3, 2, 1]), [1, 2, 3])
|
|
3143
|
+
*
|
|
3144
|
+
* @category combinators
|
|
3145
|
+
* @since 2.0.0
|
|
3146
|
+
*/
|
|
3147
|
+
var sort = function (O) { return function (as) {
|
|
3148
|
+
return as.length <= 1 ? (0, exports.copy)(as) : as.slice().sort(O.compare);
|
|
3149
|
+
}; };
|
|
3150
|
+
exports.sort = sort;
|
|
3151
|
+
/**
|
|
3152
|
+
* Apply a function to pairs of elements at the same index in two arrays, collecting the results in a new array. If one
|
|
3153
|
+
* input array is short, excess elements of the longer array are discarded.
|
|
3154
|
+
*
|
|
3155
|
+
* @example
|
|
3156
|
+
* import { zipWith } from 'fp-ts/Array'
|
|
3157
|
+
*
|
|
3158
|
+
* assert.deepStrictEqual(zipWith([1, 2, 3], ['a', 'b', 'c', 'd'], (n, s) => s + n), ['a1', 'b2', 'c3'])
|
|
3159
|
+
*
|
|
3160
|
+
* @category combinators
|
|
3161
|
+
* @since 2.0.0
|
|
3162
|
+
*/
|
|
3163
|
+
var zipWith = function (fa, fb, f) {
|
|
3164
|
+
var fc = [];
|
|
3165
|
+
var len = Math.min(fa.length, fb.length);
|
|
3166
|
+
for (var i = 0; i < len; i++) {
|
|
3167
|
+
fc[i] = f(fa[i], fb[i]);
|
|
3168
|
+
}
|
|
3169
|
+
return fc;
|
|
3170
|
+
};
|
|
3171
|
+
exports.zipWith = zipWith;
|
|
3172
|
+
function zip(as, bs) {
|
|
3173
|
+
if (bs === undefined) {
|
|
3174
|
+
return function (bs) { return zip(bs, as); };
|
|
3175
|
+
}
|
|
3176
|
+
return (0, exports.zipWith)(as, bs, function (a, b) { return [a, b]; });
|
|
3177
|
+
}
|
|
3178
|
+
exports.zip = zip;
|
|
3179
|
+
/**
|
|
3180
|
+
* The function is reverse of `zip`. Takes an array of pairs and return two corresponding arrays
|
|
3181
|
+
*
|
|
3182
|
+
* @example
|
|
3183
|
+
* import { unzip } from 'fp-ts/Array'
|
|
3184
|
+
*
|
|
3185
|
+
* assert.deepStrictEqual(unzip([[1, 'a'], [2, 'b'], [3, 'c']]), [[1, 2, 3], ['a', 'b', 'c']])
|
|
3186
|
+
*
|
|
3187
|
+
* @since 2.0.0
|
|
3188
|
+
*/
|
|
3189
|
+
var unzip = function (as) {
|
|
3190
|
+
var fa = [];
|
|
3191
|
+
var fb = [];
|
|
3192
|
+
for (var i = 0; i < as.length; i++) {
|
|
3193
|
+
fa[i] = as[i][0];
|
|
3194
|
+
fb[i] = as[i][1];
|
|
3195
|
+
}
|
|
3196
|
+
return [fa, fb];
|
|
3197
|
+
};
|
|
3198
|
+
exports.unzip = unzip;
|
|
3199
|
+
/**
|
|
3200
|
+
* Creates a new `Array`, prepending an element to every member of the input `Array`.
|
|
3201
|
+
*
|
|
3202
|
+
* @example
|
|
3203
|
+
* import { prependAll } from 'fp-ts/Array'
|
|
3204
|
+
*
|
|
3205
|
+
* assert.deepStrictEqual(prependAll(9)([1, 2, 3, 4]), [9, 1, 9, 2, 9, 3, 9, 4])
|
|
3206
|
+
*
|
|
3207
|
+
* @category combinators
|
|
3208
|
+
* @since 2.10.0
|
|
3209
|
+
*/
|
|
3210
|
+
var prependAll = function (middle) {
|
|
3211
|
+
var f = NEA.prependAll(middle);
|
|
3212
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : []); };
|
|
3213
|
+
};
|
|
3214
|
+
exports.prependAll = prependAll;
|
|
3215
|
+
/**
|
|
3216
|
+
* Creates a new `Array` placing an element in between members of the input `Array`.
|
|
3217
|
+
*
|
|
3218
|
+
* @example
|
|
3219
|
+
* import { intersperse } from 'fp-ts/Array'
|
|
3220
|
+
*
|
|
3221
|
+
* assert.deepStrictEqual(intersperse(9)([1, 2, 3, 4]), [1, 9, 2, 9, 3, 9, 4])
|
|
3222
|
+
*
|
|
3223
|
+
* @category combinators
|
|
3224
|
+
* @since 2.9.0
|
|
3225
|
+
*/
|
|
3226
|
+
var intersperse = function (middle) {
|
|
3227
|
+
var f = NEA.intersperse(middle);
|
|
3228
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : (0, exports.copy)(as)); };
|
|
3229
|
+
};
|
|
3230
|
+
exports.intersperse = intersperse;
|
|
3231
|
+
/**
|
|
3232
|
+
* Creates a new `Array` rotating the input `Array` by `n` steps.
|
|
3233
|
+
*
|
|
3234
|
+
* @example
|
|
3235
|
+
* import { rotate } from 'fp-ts/Array'
|
|
3236
|
+
*
|
|
3237
|
+
* assert.deepStrictEqual(rotate(2)([1, 2, 3, 4, 5]), [4, 5, 1, 2, 3])
|
|
3238
|
+
*
|
|
3239
|
+
* @category combinators
|
|
3240
|
+
* @since 2.0.0
|
|
3241
|
+
*/
|
|
3242
|
+
var rotate = function (n) {
|
|
3243
|
+
var f = NEA.rotate(n);
|
|
3244
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : (0, exports.copy)(as)); };
|
|
3245
|
+
};
|
|
3246
|
+
exports.rotate = rotate;
|
|
3247
|
+
// TODO: remove non-curried overloading in v3
|
|
3248
|
+
/**
|
|
3249
|
+
* Test if a value is a member of an `Array`. Takes a `Eq<A>` as a single
|
|
3250
|
+
* argument which returns the function to use to search for a value of type `A` in
|
|
3251
|
+
* an `Array<A>`.
|
|
3252
|
+
*
|
|
3253
|
+
* @example
|
|
3254
|
+
* import { elem } from 'fp-ts/Array'
|
|
3255
|
+
* import * as N from 'fp-ts/number'
|
|
3256
|
+
* import { pipe } from 'fp-ts/function'
|
|
3257
|
+
*
|
|
3258
|
+
* assert.strictEqual(pipe([1, 2, 3], elem(N.Eq)(2)), true)
|
|
3259
|
+
* assert.strictEqual(pipe([1, 2, 3], elem(N.Eq)(0)), false)
|
|
3260
|
+
*
|
|
3261
|
+
* @since 2.0.0
|
|
3262
|
+
*/
|
|
3263
|
+
exports.elem = RA.elem;
|
|
3264
|
+
/**
|
|
3265
|
+
* Creates a new `Array` removing duplicate elements, keeping the first occurrence of an element,
|
|
3266
|
+
* based on a `Eq<A>`.
|
|
3267
|
+
*
|
|
3268
|
+
* @example
|
|
3269
|
+
* import { uniq } from 'fp-ts/Array'
|
|
3270
|
+
* import * as N from 'fp-ts/number'
|
|
3271
|
+
*
|
|
3272
|
+
* assert.deepStrictEqual(uniq(N.Eq)([1, 2, 1]), [1, 2])
|
|
3273
|
+
*
|
|
3274
|
+
* @category combinators
|
|
3275
|
+
* @since 2.0.0
|
|
3276
|
+
*/
|
|
3277
|
+
var uniq = function (E) {
|
|
3278
|
+
var f = NEA.uniq(E);
|
|
3279
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : (0, exports.copy)(as)); };
|
|
3280
|
+
};
|
|
3281
|
+
exports.uniq = uniq;
|
|
3282
|
+
/**
|
|
3283
|
+
* Sort the elements of an array in increasing order, where elements are compared using first `ords[0]`, then `ords[1]`,
|
|
3284
|
+
* etc...
|
|
3285
|
+
*
|
|
3286
|
+
* @example
|
|
3287
|
+
* import { sortBy } from 'fp-ts/Array'
|
|
3288
|
+
* import { contramap } from 'fp-ts/Ord'
|
|
3289
|
+
* import * as S from 'fp-ts/string'
|
|
3290
|
+
* import * as N from 'fp-ts/number'
|
|
3291
|
+
* import { pipe } from 'fp-ts/function'
|
|
3292
|
+
*
|
|
3293
|
+
* interface Person {
|
|
3294
|
+
* readonly name: string
|
|
3295
|
+
* readonly age: number
|
|
3296
|
+
* }
|
|
3297
|
+
* const byName = pipe(S.Ord, contramap((p: Person) => p.name))
|
|
3298
|
+
* const byAge = pipe(N.Ord, contramap((p: Person) => p.age))
|
|
3299
|
+
*
|
|
3300
|
+
* const sortByNameByAge = sortBy([byName, byAge])
|
|
3301
|
+
*
|
|
3302
|
+
* const persons = [{ name: 'a', age: 1 }, { name: 'b', age: 3 }, { name: 'c', age: 2 }, { name: 'b', age: 2 }]
|
|
3303
|
+
* assert.deepStrictEqual(sortByNameByAge(persons), [
|
|
3304
|
+
* { name: 'a', age: 1 },
|
|
3305
|
+
* { name: 'b', age: 2 },
|
|
3306
|
+
* { name: 'b', age: 3 },
|
|
3307
|
+
* { name: 'c', age: 2 }
|
|
3308
|
+
* ])
|
|
3309
|
+
*
|
|
3310
|
+
* @category combinators
|
|
3311
|
+
* @since 2.0.0
|
|
3312
|
+
*/
|
|
3313
|
+
var sortBy = function (ords) {
|
|
3314
|
+
var f = NEA.sortBy(ords);
|
|
3315
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : (0, exports.copy)(as)); };
|
|
3316
|
+
};
|
|
3317
|
+
exports.sortBy = sortBy;
|
|
3318
|
+
/**
|
|
3319
|
+
* A useful recursion pattern for processing an array to produce a new array, often used for "chopping" up the input
|
|
3320
|
+
* array. Typically chop is called with some function that will consume an initial prefix of the array and produce a
|
|
3321
|
+
* value and the rest of the array.
|
|
3322
|
+
*
|
|
3323
|
+
* @example
|
|
3324
|
+
* import { Eq } from 'fp-ts/Eq'
|
|
3325
|
+
* import * as A from 'fp-ts/Array'
|
|
3326
|
+
* import * as N from 'fp-ts/number'
|
|
3327
|
+
* import { pipe } from 'fp-ts/function'
|
|
3328
|
+
*
|
|
3329
|
+
* const group = <A>(S: Eq<A>): ((as: Array<A>) => Array<Array<A>>) => {
|
|
3330
|
+
* return A.chop(as => {
|
|
3331
|
+
* const { init, rest } = pipe(as, A.spanLeft((a: A) => S.equals(a, as[0])))
|
|
3332
|
+
* return [init, rest]
|
|
3333
|
+
* })
|
|
3334
|
+
* }
|
|
3335
|
+
* assert.deepStrictEqual(group(N.Eq)([1, 1, 2, 3, 3, 4]), [[1, 1], [2], [3, 3], [4]])
|
|
3336
|
+
*
|
|
3337
|
+
* @category combinators
|
|
3338
|
+
* @since 2.0.0
|
|
3339
|
+
*/
|
|
3340
|
+
var chop = function (f) {
|
|
3341
|
+
var g = NEA.chop(f);
|
|
3342
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? g(as) : []); };
|
|
3343
|
+
};
|
|
3344
|
+
exports.chop = chop;
|
|
3345
|
+
/**
|
|
3346
|
+
* Splits an `Array` into two pieces, the first piece has max `n` elements.
|
|
3347
|
+
*
|
|
3348
|
+
* @example
|
|
3349
|
+
* import { splitAt } from 'fp-ts/Array'
|
|
3350
|
+
*
|
|
3351
|
+
* assert.deepStrictEqual(splitAt(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4, 5]])
|
|
3352
|
+
*
|
|
3353
|
+
* @category combinators
|
|
3354
|
+
* @since 2.0.0
|
|
3355
|
+
*/
|
|
3356
|
+
var splitAt = function (n) { return function (as) {
|
|
3357
|
+
return n >= 1 && (0, exports.isNonEmpty)(as) ? NEA.splitAt(n)(as) : (0, exports.isEmpty)(as) ? [(0, exports.copy)(as), []] : [[], (0, exports.copy)(as)];
|
|
3358
|
+
}; };
|
|
3359
|
+
exports.splitAt = splitAt;
|
|
3360
|
+
/**
|
|
3361
|
+
* Splits an array into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
3362
|
+
* the array. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
3363
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
3364
|
+
*
|
|
3365
|
+
* ```ts
|
|
3366
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
3367
|
+
* ```
|
|
3368
|
+
*
|
|
3369
|
+
* whenever `n` evenly divides the length of `xs`.
|
|
3370
|
+
*
|
|
3371
|
+
* @example
|
|
3372
|
+
* import { chunksOf } from 'fp-ts/Array'
|
|
3373
|
+
*
|
|
3374
|
+
* assert.deepStrictEqual(chunksOf(2)([1, 2, 3, 4, 5]), [[1, 2], [3, 4], [5]])
|
|
3375
|
+
*
|
|
3376
|
+
* @category combinators
|
|
3377
|
+
* @since 2.0.0
|
|
3378
|
+
*/
|
|
3379
|
+
var chunksOf = function (n) {
|
|
3380
|
+
var f = NEA.chunksOf(n);
|
|
3381
|
+
return function (as) { return ((0, exports.isNonEmpty)(as) ? f(as) : []); };
|
|
3382
|
+
};
|
|
3383
|
+
exports.chunksOf = chunksOf;
|
|
3384
|
+
/**
|
|
3385
|
+
* @category combinators
|
|
3386
|
+
* @since 2.11.0
|
|
3387
|
+
*/
|
|
3388
|
+
var fromOptionK = function (f) { return function () {
|
|
3389
|
+
var a = [];
|
|
3390
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3391
|
+
a[_i] = arguments[_i];
|
|
3392
|
+
}
|
|
3393
|
+
return (0, exports.fromOption)(f.apply(void 0, a));
|
|
3394
|
+
}; };
|
|
3395
|
+
exports.fromOptionK = fromOptionK;
|
|
3396
|
+
function comprehension(input, f, g) {
|
|
3397
|
+
if (g === void 0) { g = function () { return true; }; }
|
|
3398
|
+
var go = function (scope, input) {
|
|
3399
|
+
return (0, exports.isNonEmpty)(input)
|
|
3400
|
+
? (0, _function.pipe)(NEA.head(input), (0, exports.chain)(function (x) { return go((0, _function.pipe)(scope, (0, exports.append)(x)), NEA.tail(input)); }))
|
|
3401
|
+
: g.apply(void 0, scope) ? [f.apply(void 0, scope)]
|
|
3402
|
+
: [];
|
|
3403
|
+
};
|
|
3404
|
+
return go([], input);
|
|
3405
|
+
}
|
|
3406
|
+
exports.comprehension = comprehension;
|
|
3407
|
+
/**
|
|
3408
|
+
* @category combinators
|
|
3409
|
+
* @since 2.11.0
|
|
3410
|
+
*/
|
|
3411
|
+
var concatW = function (second) { return function (first) {
|
|
3412
|
+
return (0, exports.isEmpty)(first) ? (0, exports.copy)(second) : (0, exports.isEmpty)(second) ? (0, exports.copy)(first) : first.concat(second);
|
|
3413
|
+
}; };
|
|
3414
|
+
exports.concatW = concatW;
|
|
3415
|
+
/**
|
|
3416
|
+
* @category combinators
|
|
3417
|
+
* @since 2.11.0
|
|
3418
|
+
*/
|
|
3419
|
+
exports.concat = exports.concatW;
|
|
3420
|
+
function union(E) {
|
|
3421
|
+
var unionE = NEA.union(E);
|
|
3422
|
+
return function (first, second) {
|
|
3423
|
+
if (second === undefined) {
|
|
3424
|
+
var unionE_1 = union(E);
|
|
3425
|
+
return function (second) { return unionE_1(second, first); };
|
|
3426
|
+
}
|
|
3427
|
+
return (0, exports.isNonEmpty)(first) && (0, exports.isNonEmpty)(second)
|
|
3428
|
+
? unionE(second)(first)
|
|
3429
|
+
: (0, exports.isNonEmpty)(first)
|
|
3430
|
+
? (0, exports.copy)(first)
|
|
3431
|
+
: (0, exports.copy)(second);
|
|
3432
|
+
};
|
|
3433
|
+
}
|
|
3434
|
+
exports.union = union;
|
|
3435
|
+
function intersection(E) {
|
|
3436
|
+
var elemE = (0, exports.elem)(E);
|
|
3437
|
+
return function (xs, ys) {
|
|
3438
|
+
if (ys === undefined) {
|
|
3439
|
+
var intersectionE_1 = intersection(E);
|
|
3440
|
+
return function (ys) { return intersectionE_1(ys, xs); };
|
|
3441
|
+
}
|
|
3442
|
+
return xs.filter(function (a) { return elemE(a, ys); });
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
3445
|
+
exports.intersection = intersection;
|
|
3446
|
+
function difference(E) {
|
|
3447
|
+
var elemE = (0, exports.elem)(E);
|
|
3448
|
+
return function (xs, ys) {
|
|
3449
|
+
if (ys === undefined) {
|
|
3450
|
+
var differenceE_1 = difference(E);
|
|
3451
|
+
return function (ys) { return differenceE_1(ys, xs); };
|
|
3452
|
+
}
|
|
3453
|
+
return xs.filter(function (a) { return !elemE(a, ys); });
|
|
3454
|
+
};
|
|
3455
|
+
}
|
|
3456
|
+
exports.difference = difference;
|
|
3457
|
+
// -------------------------------------------------------------------------------------
|
|
3458
|
+
// non-pipeables
|
|
3459
|
+
// -------------------------------------------------------------------------------------
|
|
3460
|
+
var _map = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.map)(f)); };
|
|
3461
|
+
/* istanbul ignore next */
|
|
3462
|
+
var _mapWithIndex = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.mapWithIndex)(f)); };
|
|
3463
|
+
var _ap = function (fab, fa) { return (0, _function.pipe)(fab, (0, exports.ap)(fa)); };
|
|
3464
|
+
var _chain = function (ma, f) { return (0, _function.pipe)(ma, (0, exports.chain)(f)); };
|
|
3465
|
+
/* istanbul ignore next */
|
|
3466
|
+
var _filter = function (fa, predicate) { return (0, _function.pipe)(fa, (0, exports.filter)(predicate)); };
|
|
3467
|
+
/* istanbul ignore next */
|
|
3468
|
+
var _filterMap = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.filterMap)(f)); };
|
|
3469
|
+
/* istanbul ignore next */
|
|
3470
|
+
var _partition = function (fa, predicate) {
|
|
3471
|
+
return (0, _function.pipe)(fa, (0, exports.partition)(predicate));
|
|
3472
|
+
};
|
|
3473
|
+
/* istanbul ignore next */
|
|
3474
|
+
var _partitionMap = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.partitionMap)(f)); };
|
|
3475
|
+
/* istanbul ignore next */
|
|
3476
|
+
var _partitionWithIndex = function (fa, predicateWithIndex) { return (0, _function.pipe)(fa, (0, exports.partitionWithIndex)(predicateWithIndex)); };
|
|
3477
|
+
/* istanbul ignore next */
|
|
3478
|
+
var _partitionMapWithIndex = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.partitionMapWithIndex)(f)); };
|
|
3479
|
+
/* istanbul ignore next */
|
|
3480
|
+
var _alt = function (fa, that) { return (0, _function.pipe)(fa, (0, exports.alt)(that)); };
|
|
3481
|
+
var _reduce = function (fa, b, f) { return (0, _function.pipe)(fa, (0, exports.reduce)(b, f)); };
|
|
3482
|
+
/* istanbul ignore next */
|
|
3483
|
+
var _foldMap = function (M) {
|
|
3484
|
+
var foldMapM = (0, exports.foldMap)(M);
|
|
3485
|
+
return function (fa, f) { return (0, _function.pipe)(fa, foldMapM(f)); };
|
|
3486
|
+
};
|
|
3487
|
+
/* istanbul ignore next */
|
|
3488
|
+
var _reduceRight = function (fa, b, f) { return (0, _function.pipe)(fa, (0, exports.reduceRight)(b, f)); };
|
|
3489
|
+
/* istanbul ignore next */
|
|
3490
|
+
var _reduceWithIndex = function (fa, b, f) {
|
|
3491
|
+
return (0, _function.pipe)(fa, (0, exports.reduceWithIndex)(b, f));
|
|
3492
|
+
};
|
|
3493
|
+
/* istanbul ignore next */
|
|
3494
|
+
var _foldMapWithIndex = function (M) {
|
|
3495
|
+
var foldMapWithIndexM = (0, exports.foldMapWithIndex)(M);
|
|
3496
|
+
return function (fa, f) { return (0, _function.pipe)(fa, foldMapWithIndexM(f)); };
|
|
3497
|
+
};
|
|
3498
|
+
/* istanbul ignore next */
|
|
3499
|
+
var _reduceRightWithIndex = function (fa, b, f) {
|
|
3500
|
+
return (0, _function.pipe)(fa, (0, exports.reduceRightWithIndex)(b, f));
|
|
3501
|
+
};
|
|
3502
|
+
/* istanbul ignore next */
|
|
3503
|
+
var _filterMapWithIndex = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.filterMapWithIndex)(f)); };
|
|
3504
|
+
/* istanbul ignore next */
|
|
3505
|
+
var _filterWithIndex = function (fa, predicateWithIndex) { return (0, _function.pipe)(fa, (0, exports.filterWithIndex)(predicateWithIndex)); };
|
|
3506
|
+
/* istanbul ignore next */
|
|
3507
|
+
var _extend = function (fa, f) { return (0, _function.pipe)(fa, (0, exports.extend)(f)); };
|
|
3508
|
+
/* istanbul ignore next */
|
|
3509
|
+
var _traverse = function (F) {
|
|
3510
|
+
var traverseF = (0, exports.traverse)(F);
|
|
3511
|
+
return function (ta, f) { return (0, _function.pipe)(ta, traverseF(f)); };
|
|
3512
|
+
};
|
|
3513
|
+
/* istanbul ignore next */
|
|
3514
|
+
var _traverseWithIndex = function (F) {
|
|
3515
|
+
var traverseWithIndexF = (0, exports.traverseWithIndex)(F);
|
|
3516
|
+
return function (ta, f) { return (0, _function.pipe)(ta, traverseWithIndexF(f)); };
|
|
3517
|
+
};
|
|
3518
|
+
var _chainRecDepthFirst = RA._chainRecDepthFirst;
|
|
3519
|
+
var _chainRecBreadthFirst = RA._chainRecBreadthFirst;
|
|
3520
|
+
// -------------------------------------------------------------------------------------
|
|
3521
|
+
// type class members
|
|
3522
|
+
// -------------------------------------------------------------------------------------
|
|
3523
|
+
/**
|
|
3524
|
+
* Given an element of the base type, `of` builds an `Array` containing just that
|
|
3525
|
+
* element of the base type (this is useful for building a `Monad`).
|
|
3526
|
+
*
|
|
3527
|
+
* @example
|
|
3528
|
+
* import { of } from 'fp-ts/Array'
|
|
3529
|
+
*
|
|
3530
|
+
* assert.deepStrictEqual(of("a"), ["a"]);
|
|
3531
|
+
*
|
|
3532
|
+
* @category Pointed
|
|
3533
|
+
* @since 2.0.0
|
|
3534
|
+
*/
|
|
3535
|
+
exports.of = NEA.of;
|
|
3536
|
+
/**
|
|
3537
|
+
* Makes an empty `Array`, useful for building a [`Monoid`](#Monoid)
|
|
3538
|
+
*
|
|
3539
|
+
* @category Zero
|
|
3540
|
+
* @since 2.7.0
|
|
3541
|
+
*/
|
|
3542
|
+
var zero = function () { return []; };
|
|
3543
|
+
exports.zero = zero;
|
|
3544
|
+
/**
|
|
3545
|
+
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: Array<A>) => Array<B>`.
|
|
3546
|
+
* In practice it applies the base function to each element of the array and collects the
|
|
3547
|
+
* results in a new array.
|
|
3548
|
+
*
|
|
3549
|
+
* @example
|
|
3550
|
+
* import { map } from 'fp-ts/Array'
|
|
3551
|
+
* import { pipe } from 'fp-ts/function'
|
|
3552
|
+
*
|
|
3553
|
+
* const f = (n: number) => n * 2;
|
|
3554
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], map(f)), [2, 4, 6]);
|
|
3555
|
+
*
|
|
3556
|
+
* @category Functor
|
|
3557
|
+
* @since 2.0.0
|
|
3558
|
+
*/
|
|
3559
|
+
var map = function (f) { return function (fa) { return fa.map(function (a) { return f(a); }); }; };
|
|
3560
|
+
exports.map = map;
|
|
3561
|
+
/**
|
|
3562
|
+
* Apply a function to an argument under a type constructor.
|
|
3563
|
+
*
|
|
3564
|
+
* It can be used to extend the concept of [`map`](#map) to a function that
|
|
3565
|
+
* takes more than one parameter as described
|
|
3566
|
+
* read [here](https://dev.to/gcanti/getting-started-with-fp-ts-applicative-1kb3)
|
|
3567
|
+
*
|
|
3568
|
+
* @example
|
|
3569
|
+
* import { ap, map, of } from 'fp-ts/Array'
|
|
3570
|
+
* import { pipe } from 'fp-ts/function'
|
|
3571
|
+
*
|
|
3572
|
+
* // a curried function with 3 input parameteres
|
|
3573
|
+
* const f = (s1: string) => (n: number) => (s2: string) => s1 + n + s2;
|
|
3574
|
+
*
|
|
3575
|
+
* // let's use `ap` to iterate `f` over an array for each input parameter
|
|
3576
|
+
* assert.deepStrictEqual(pipe(["a", "b"], map(f), ap([1, 2]), ap(["😀", "😫", "😎"])), [
|
|
3577
|
+
* "a1😀", "a1😫", "a1😎",
|
|
3578
|
+
* "a2😀", "a2😫", "a2😎",
|
|
3579
|
+
* "b1😀", "b1😫", "b1😎",
|
|
3580
|
+
* "b2😀", "b2😫", "b2😎",
|
|
3581
|
+
* ]);
|
|
3582
|
+
*
|
|
3583
|
+
* // given Array implements the Applicative interface with the `of` method,
|
|
3584
|
+
* // we can write exactly the same thing in a more symmetric way
|
|
3585
|
+
* // using `of` on `f` and `ap` on each array in input
|
|
3586
|
+
* assert.deepStrictEqual(
|
|
3587
|
+
* pipe(of(f), ap(["a", "b"]), ap([1, 2]), ap(["😀", "😫", "😎"])),
|
|
3588
|
+
* pipe(["a", "b"], map(f), ap([1, 2]), ap(["😀", "😫", "😎"]))
|
|
3589
|
+
* );
|
|
3590
|
+
*
|
|
3591
|
+
* @category Apply
|
|
3592
|
+
* @since 2.0.0
|
|
3593
|
+
*/
|
|
3594
|
+
var ap = function (fa) { return (0, exports.chain)(function (f) { return (0, _function.pipe)(fa, (0, exports.map)(f)); }); };
|
|
3595
|
+
exports.ap = ap;
|
|
3596
|
+
/**
|
|
3597
|
+
* Composes computations in sequence, using the return value of one computation to
|
|
3598
|
+
* determine the next computation.
|
|
3599
|
+
*
|
|
3600
|
+
* In other words it takes a function `f` that produces an array from a single element of
|
|
3601
|
+
* the base type `A` and returns a new function which applies `f` to each element of the
|
|
3602
|
+
* input array (like [`map`](#map)) and, instead of returning an array of arrays, concatenates the
|
|
3603
|
+
* results into a single array (like [`flatten`](#flatten)).
|
|
3604
|
+
*
|
|
3605
|
+
* This is the `chain` component of the array `Monad`.
|
|
3606
|
+
*
|
|
3607
|
+
* @example
|
|
3608
|
+
* import { chain, map, replicate } from 'fp-ts/Array'
|
|
3609
|
+
* import { pipe } from 'fp-ts/function'
|
|
3610
|
+
*
|
|
3611
|
+
* const f = (n: number) => replicate(n, `${n}`);
|
|
3612
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], map(f)), [["1"], ["2", "2"], ["3", "3", "3"]]);
|
|
3613
|
+
* assert.deepStrictEqual(pipe([1, 2, 3], chain(f)), ["1", "2", "2", "3", "3", "3"]);
|
|
3614
|
+
*
|
|
3615
|
+
* @category Monad
|
|
3616
|
+
* @since 2.0.0
|
|
3617
|
+
*/
|
|
3618
|
+
var chain = function (f) { return function (ma) {
|
|
3619
|
+
return (0, _function.pipe)(ma, (0, exports.chainWithIndex)(function (_, a) { return f(a); }));
|
|
3620
|
+
}; };
|
|
3621
|
+
exports.chain = chain;
|
|
3622
|
+
/**
|
|
3623
|
+
* Takes an array of arrays of `A` and flattens them into an array of `A`
|
|
3624
|
+
* by concatenating the elements of each array in order.
|
|
3625
|
+
*
|
|
3626
|
+
* Derivable from [`chain`](#chain).
|
|
3627
|
+
*
|
|
3628
|
+
* @example
|
|
3629
|
+
* import { flatten } from 'fp-ts/Array'
|
|
3630
|
+
*
|
|
3631
|
+
* assert.deepStrictEqual(flatten([["a"], ["b", "c"], ["d", "e", "f"]]), ["a", "b", "c", "d", "e", "f"]);
|
|
3632
|
+
*
|
|
3633
|
+
* @category combinators
|
|
3634
|
+
* @since 2.5.0
|
|
3635
|
+
*/
|
|
3636
|
+
exports.flatten = (0, exports.chain)(_function.identity);
|
|
3637
|
+
/**
|
|
3638
|
+
* Same as [`map`](#map), but the iterating function takes both the index and the value
|
|
3639
|
+
* of the element.
|
|
3640
|
+
*
|
|
3641
|
+
* @example
|
|
3642
|
+
* import { mapWithIndex } from 'fp-ts/Array'
|
|
3643
|
+
* import { pipe } from 'fp-ts/function'
|
|
3644
|
+
*
|
|
3645
|
+
* const f = (i: number, s: string) => `${s} - ${i}`;
|
|
3646
|
+
* assert.deepStrictEqual(pipe(["a", "b", "c"], mapWithIndex(f)), ["a - 0", "b - 1", "c - 2"]);
|
|
3647
|
+
*
|
|
3648
|
+
* @category FunctorWithIndex
|
|
3649
|
+
* @since 2.0.0
|
|
3650
|
+
*/
|
|
3651
|
+
var mapWithIndex = function (f) { return function (fa) {
|
|
3652
|
+
return fa.map(function (a, i) { return f(i, a); });
|
|
3653
|
+
}; };
|
|
3654
|
+
exports.mapWithIndex = mapWithIndex;
|
|
3655
|
+
/**
|
|
3656
|
+
* Maps an array with an iterating function that takes the index and the value of
|
|
3657
|
+
* each element and returns an `Option`. It keeps only the `Some` values discarding
|
|
3658
|
+
* the `None`s.
|
|
3659
|
+
*
|
|
3660
|
+
* Same as [`filterMap`](#filterMap), but with an iterating function which takes also
|
|
3661
|
+
* the index as input.
|
|
3662
|
+
*
|
|
3663
|
+
* @example
|
|
3664
|
+
* import { filterMapWithIndex } from 'fp-ts/Array'
|
|
3665
|
+
* import { pipe } from 'fp-ts/function'
|
|
3666
|
+
* import { option } from "fp-ts";
|
|
3667
|
+
*
|
|
3668
|
+
* const f = (i: number, s: string) => (i % 2 === 1 ? option.some(s.toUpperCase()) : option.none);
|
|
3669
|
+
* assert.deepStrictEqual(pipe(["a", "no", "neither", "b"], filterMapWithIndex(f)), ["NO", "B"]);
|
|
3670
|
+
*
|
|
3671
|
+
* @category FilterableWithIndex
|
|
3672
|
+
* @since 2.0.0
|
|
3673
|
+
*/
|
|
3674
|
+
var filterMapWithIndex = function (f) { return function (fa) {
|
|
3675
|
+
var out = [];
|
|
3676
|
+
for (var i = 0; i < fa.length; i++) {
|
|
3677
|
+
var optionB = f(i, fa[i]);
|
|
3678
|
+
if (_.isSome(optionB)) {
|
|
3679
|
+
out.push(optionB.value);
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
return out;
|
|
3683
|
+
}; };
|
|
3684
|
+
exports.filterMapWithIndex = filterMapWithIndex;
|
|
3685
|
+
/**
|
|
3686
|
+
* Maps an array with an iterating function that returns an `Option`
|
|
3687
|
+
* and it keeps only the `Some` values discarding the `None`s.
|
|
3688
|
+
*
|
|
3689
|
+
* @example
|
|
3690
|
+
* import { filterMap } from 'fp-ts/Array'
|
|
3691
|
+
* import { pipe } from 'fp-ts/function'
|
|
3692
|
+
* import { option } from "fp-ts";
|
|
3693
|
+
*
|
|
3694
|
+
* const f = (s: string) => s.length === 1 ? option.some(s.toUpperCase()) : option.none;
|
|
3695
|
+
* assert.deepStrictEqual(pipe(["a", "no", "neither", "b"], filterMap(f)), ["A", "B"]);
|
|
3696
|
+
*
|
|
3697
|
+
* @category Filterable
|
|
3698
|
+
* @since 2.0.0
|
|
3699
|
+
*/
|
|
3700
|
+
var filterMap = function (f) {
|
|
3701
|
+
return (0, exports.filterMapWithIndex)(function (_, a) { return f(a); });
|
|
3702
|
+
};
|
|
3703
|
+
exports.filterMap = filterMap;
|
|
3704
|
+
/**
|
|
3705
|
+
* Compact an array of `Option`s discarding the `None` values and
|
|
3706
|
+
* keeping the `Some` values. It returns a new array containing the values of
|
|
3707
|
+
* the `Some` options.
|
|
3708
|
+
*
|
|
3709
|
+
* @example
|
|
3710
|
+
* import { compact } from 'fp-ts/Array'
|
|
3711
|
+
* import { option } from "fp-ts";
|
|
3712
|
+
*
|
|
3713
|
+
* assert.deepStrictEqual(compact([option.some("a"), option.none, option.some("b")]), ["a", "b"]);
|
|
3714
|
+
*
|
|
3715
|
+
* @category Compactable
|
|
3716
|
+
* @since 2.0.0
|
|
3717
|
+
*/
|
|
3718
|
+
exports.compact = (0, exports.filterMap)(_function.identity);
|
|
3719
|
+
/**
|
|
3720
|
+
* Separate an array of `Either`s into `Left`s and `Right`s, creating two new arrays:
|
|
3721
|
+
* one containing all the left values and one containing all the right values.
|
|
3722
|
+
*
|
|
3723
|
+
* @example
|
|
3724
|
+
* import { separate } from 'fp-ts/Array'
|
|
3725
|
+
* import { either } from "fp-ts";
|
|
3726
|
+
*
|
|
3727
|
+
* assert.deepStrictEqual(separate([either.right("r1"), either.left("l1"), either.right("r2")]), {
|
|
3728
|
+
* left: ["l1"],
|
|
3729
|
+
* right: ["r1", "r2"],
|
|
3730
|
+
* });
|
|
3731
|
+
*
|
|
3732
|
+
* @category Compactable
|
|
3733
|
+
* @since 2.0.0
|
|
3734
|
+
*/
|
|
3735
|
+
var separate = function (fa) {
|
|
3736
|
+
var left = [];
|
|
3737
|
+
var right = [];
|
|
3738
|
+
for (var _i = 0, fa_1 = fa; _i < fa_1.length; _i++) {
|
|
3739
|
+
var e = fa_1[_i];
|
|
3740
|
+
if (e._tag === 'Left') {
|
|
3741
|
+
left.push(e.left);
|
|
3742
|
+
}
|
|
3743
|
+
else {
|
|
3744
|
+
right.push(e.right);
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
return (0, Separated.separated)(left, right);
|
|
3748
|
+
};
|
|
3749
|
+
exports.separate = separate;
|
|
3750
|
+
/**
|
|
3751
|
+
* Given an iterating function that is a `Predicate` or a `Refinement`,
|
|
3752
|
+
* `filter` creates a new `Array` containing the elements of the original
|
|
3753
|
+
* `Array` for which the iterating function is `true`.
|
|
3754
|
+
*
|
|
3755
|
+
* @example
|
|
3756
|
+
* import { filter } from 'fp-ts/Array'
|
|
3757
|
+
* import { isString } from "fp-ts/lib/string";
|
|
3758
|
+
*
|
|
3759
|
+
* assert.deepStrictEqual(filter(isString)(["a", 1, {}, "b", 5]), ["a", "b"]);
|
|
3760
|
+
* assert.deepStrictEqual(filter((x:number) => x > 0)([-3, 1, -2, 5]), [1, 5]);
|
|
3761
|
+
*
|
|
3762
|
+
* @category Filterable
|
|
3763
|
+
* @since 2.0.0
|
|
3764
|
+
*/
|
|
3765
|
+
var filter = function (predicate) { return function (as) { return as.filter(predicate); }; };
|
|
3766
|
+
exports.filter = filter;
|
|
3767
|
+
/**
|
|
3768
|
+
* Given an iterating function that is a `Predicate` or a `Refinement`,
|
|
3769
|
+
* `partition` creates two new `Array`s: `right` containing the elements of the original
|
|
3770
|
+
* `Array` for which the iterating function is `true`, `left` containing the elements
|
|
3771
|
+
* for which it is false.
|
|
3772
|
+
*
|
|
3773
|
+
* @example
|
|
3774
|
+
* import { partition } from 'fp-ts/Array'
|
|
3775
|
+
* import { isString } from "fp-ts/lib/string";
|
|
3776
|
+
*
|
|
3777
|
+
* assert.deepStrictEqual(partition(isString)(["a", 1, {}, "b", 5]), { left: [1, {}, 5], right: ["a", "b"] });
|
|
3778
|
+
* assert.deepStrictEqual(partition((x: number) => x > 0)([-3, 1, -2, 5]), { left: [-3, -2], right: [1, 5] });
|
|
3779
|
+
*
|
|
3780
|
+
* @category Filterable
|
|
3781
|
+
* @since 2.0.0
|
|
3782
|
+
*/
|
|
3783
|
+
var partition = function (predicate) {
|
|
3784
|
+
return (0, exports.partitionWithIndex)(function (_, a) { return predicate(a); });
|
|
3785
|
+
};
|
|
3786
|
+
exports.partition = partition;
|
|
3787
|
+
/**
|
|
3788
|
+
* Same as [`partition`](#partition), but passing also the index to the iterating function.
|
|
3789
|
+
*
|
|
3790
|
+
* @example
|
|
3791
|
+
* import { partitionWithIndex } from 'fp-ts/Array'
|
|
3792
|
+
*
|
|
3793
|
+
* assert.deepStrictEqual(partitionWithIndex((index, x: number) => index < 3 && x > 0)([-2, 5, 6, 7]), {
|
|
3794
|
+
* left: [-2, 7],
|
|
3795
|
+
* right: [5, 6],
|
|
3796
|
+
* });
|
|
3797
|
+
*
|
|
3798
|
+
* @category FilterableWithIndex
|
|
3799
|
+
* @since 2.0.0
|
|
3800
|
+
*/
|
|
3801
|
+
var partitionWithIndex = function (predicateWithIndex) { return function (as) {
|
|
3802
|
+
var left = [];
|
|
3803
|
+
var right = [];
|
|
3804
|
+
for (var i = 0; i < as.length; i++) {
|
|
3805
|
+
var b = as[i];
|
|
3806
|
+
if (predicateWithIndex(i, b)) {
|
|
3807
|
+
right.push(b);
|
|
3808
|
+
}
|
|
3809
|
+
else {
|
|
3810
|
+
left.push(b);
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
return (0, Separated.separated)(left, right);
|
|
3814
|
+
}; };
|
|
3815
|
+
exports.partitionWithIndex = partitionWithIndex;
|
|
3816
|
+
/**
|
|
3817
|
+
* Given an iterating function that returns an `Either`,
|
|
3818
|
+
* `partitionMap` applies the iterating function to each element and it creates two `Array`s:
|
|
3819
|
+
* `right` containing the values of `Right` results, `left` containing the values of `Left` results.
|
|
3820
|
+
*
|
|
3821
|
+
* @example
|
|
3822
|
+
* import { partitionMap } from 'fp-ts/Array'
|
|
3823
|
+
* import { Either, left, right } from "fp-ts/lib/Either";
|
|
3824
|
+
*
|
|
3825
|
+
* const upperIfString = <B>(x: B): Either<B, string> =>
|
|
3826
|
+
* typeof x === "string" ? right(x.toUpperCase()) : left(x);
|
|
3827
|
+
* assert.deepStrictEqual(partitionMap(upperIfString)([-2, "hello", 6, 7, "world"]), {
|
|
3828
|
+
* left: [-2, 6, 7],
|
|
3829
|
+
* right: [ 'HELLO', 'WORLD' ],
|
|
3830
|
+
* });
|
|
3831
|
+
*
|
|
3832
|
+
* @category Filterable
|
|
3833
|
+
* @since 2.0.0
|
|
3834
|
+
*/
|
|
3835
|
+
var partitionMap = function (f) { return (0, exports.partitionMapWithIndex)(function (_, a) { return f(a); }); };
|
|
3836
|
+
exports.partitionMap = partitionMap;
|
|
3837
|
+
/**
|
|
3838
|
+
* Same as [`partitionMap`](#partitionMap), but passing also the index to the iterating function.
|
|
3839
|
+
*
|
|
3840
|
+
* @example
|
|
3841
|
+
* import { partitionMapWithIndex } from 'fp-ts/Array'
|
|
3842
|
+
* import { Either, left, right } from "fp-ts/lib/Either";
|
|
3843
|
+
*
|
|
3844
|
+
* const upperIfStringBefore3 = <B>(index: number, x: B): Either<B, string> =>
|
|
3845
|
+
* index < 3 && typeof x === "string" ? right(x.toUpperCase()) : left(x);
|
|
3846
|
+
* assert.deepStrictEqual(partitionMapWithIndex(upperIfStringBefore3)([-2, "hello", 6, 7, "world"]), {
|
|
3847
|
+
* left: [-2, 6, 7, "world"],
|
|
3848
|
+
* right: ["HELLO"],
|
|
3849
|
+
* });
|
|
3850
|
+
*
|
|
3851
|
+
* @category FilterableWithIndex
|
|
3852
|
+
* @since 2.0.0
|
|
3853
|
+
*/
|
|
3854
|
+
var partitionMapWithIndex = function (f) { return function (fa) {
|
|
3855
|
+
var left = [];
|
|
3856
|
+
var right = [];
|
|
3857
|
+
for (var i = 0; i < fa.length; i++) {
|
|
3858
|
+
var e = f(i, fa[i]);
|
|
3859
|
+
if (e._tag === 'Left') {
|
|
3860
|
+
left.push(e.left);
|
|
3861
|
+
}
|
|
3862
|
+
else {
|
|
3863
|
+
right.push(e.right);
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
return (0, Separated.separated)(left, right);
|
|
3867
|
+
}; };
|
|
3868
|
+
exports.partitionMapWithIndex = partitionMapWithIndex;
|
|
3869
|
+
/**
|
|
3870
|
+
* Less strict version of [`alt`](#alt), it can concatenate `Array`s of different base types.
|
|
3871
|
+
*
|
|
3872
|
+
* @example
|
|
3873
|
+
* import { altW } from 'fp-ts/Array';
|
|
3874
|
+
*
|
|
3875
|
+
* assert.deepStrictEqual(altW(() => [2, 3, 4])(["a"]), ["a", 2, 3, 4]);
|
|
3876
|
+
*
|
|
3877
|
+
* @category Alt
|
|
3878
|
+
* @since 2.9.0
|
|
3879
|
+
*/
|
|
3880
|
+
var altW = function (that) { return function (fa) { return fa.concat(that()); }; };
|
|
3881
|
+
exports.altW = altW;
|
|
3882
|
+
/**
|
|
3883
|
+
* `alt` implements the `Alt` iterface by concatenation of `Array`s.
|
|
3884
|
+
* `Alt` interface is similar to `Semigroup` for higher-kinded types such
|
|
3885
|
+
* as `Array` and `Option`: the example below shows both `Alt`'s `alt` and
|
|
3886
|
+
* `Semigroup`'s `concat` functions.
|
|
3887
|
+
*
|
|
3888
|
+
* @example
|
|
3889
|
+
* import { alt, concat } from 'fp-ts/Array';
|
|
3890
|
+
*
|
|
3891
|
+
* assert.deepStrictEqual(alt(() => [2, 3, 4])([1]), [1, 2, 3, 4]);
|
|
3892
|
+
* assert.deepStrictEqual(concat([2, 3, 4])([1]), [1, 2, 3, 4]);
|
|
3893
|
+
*
|
|
3894
|
+
* @category Alt
|
|
3895
|
+
* @since 2.0.0
|
|
3896
|
+
*/
|
|
3897
|
+
exports.alt = exports.altW;
|
|
3898
|
+
/**
|
|
3899
|
+
* Same as [`filter`](#filter), but passing also the index to the iterating function.
|
|
3900
|
+
*
|
|
3901
|
+
* @example
|
|
3902
|
+
* import { filterWithIndex } from 'fp-ts/Array';
|
|
3903
|
+
*
|
|
3904
|
+
* const f = (index: number, x: number) => x > 0 && index <= 2;
|
|
3905
|
+
* assert.deepStrictEqual(filterWithIndex(f)([-3, 1, -2, 5]), [1]);
|
|
3906
|
+
*
|
|
3907
|
+
* @category FilterableWithIndex
|
|
3908
|
+
* @since 2.0.0
|
|
3909
|
+
*/
|
|
3910
|
+
var filterWithIndex = function (predicateWithIndex) { return function (as) {
|
|
3911
|
+
return as.filter(function (b, i) { return predicateWithIndex(i, b); });
|
|
3912
|
+
}; };
|
|
3913
|
+
exports.filterWithIndex = filterWithIndex;
|
|
3914
|
+
/**
|
|
3915
|
+
* Given an iterating function that takes `Array<A>` as input, `extend` returns
|
|
3916
|
+
* an array containing the results of the iterating function applied to the whole input
|
|
3917
|
+
* `Array`, then to the input `Array` without the first element, then to the input
|
|
3918
|
+
* `Array` without the first two elements, etc.
|
|
3919
|
+
*
|
|
3920
|
+
* @example
|
|
3921
|
+
* import { extend } from 'fp-ts/Array'
|
|
3922
|
+
*
|
|
3923
|
+
* const f = (a: string[]) => a.join(",");
|
|
3924
|
+
* assert.deepStrictEqual(extend(f)(["a", "b", "c"]), ["a,b,c", "b,c", "c"]);
|
|
3925
|
+
*
|
|
3926
|
+
* @category Extend
|
|
3927
|
+
* @since 2.0.0
|
|
3928
|
+
*/
|
|
3929
|
+
var extend = function (f) { return function (wa) {
|
|
3930
|
+
return wa.map(function (_, i) { return f(wa.slice(i)); });
|
|
3931
|
+
}; };
|
|
3932
|
+
exports.extend = extend;
|
|
3933
|
+
/**
|
|
3934
|
+
* `duplicate` returns an array containing the whole input `Array`,
|
|
3935
|
+
* then to the input `Array` dropping the first element, then to the input
|
|
3936
|
+
* `Array` dropping the first two elements, etc.
|
|
3937
|
+
* Derivable from `Extend`.
|
|
3938
|
+
*
|
|
3939
|
+
* @example
|
|
3940
|
+
* import { duplicate } from 'fp-ts/Array'
|
|
3941
|
+
*
|
|
3942
|
+
* assert.deepStrictEqual(duplicate(["a", "b", "c"]), [["a", "b", "c"], ["b", "c"], ["c"]]);
|
|
3943
|
+
*
|
|
3944
|
+
* @category combinators
|
|
3945
|
+
* @since 2.0.0
|
|
3946
|
+
*/
|
|
3947
|
+
exports.duplicate = (0, exports.extend)(_function.identity);
|
|
3948
|
+
/**
|
|
3949
|
+
* Map and fold an `Array`.
|
|
3950
|
+
* Map the `Array` passing each value to the iterating function.
|
|
3951
|
+
* Then fold the results using the provided `Monoid`.
|
|
3952
|
+
*
|
|
3953
|
+
* @example
|
|
3954
|
+
* import { foldMap } from 'fp-ts/Array'
|
|
3955
|
+
*
|
|
3956
|
+
* const monoid = { concat: (a: string, b: string) => a + b, empty: "" };
|
|
3957
|
+
* const f = (s: string) => s.toUpperCase()
|
|
3958
|
+
* assert.deepStrictEqual(foldMap(monoid)(f)(["a", "b", "c"]), "ABC");
|
|
3959
|
+
*
|
|
3960
|
+
* @category Foldable
|
|
3961
|
+
* @since 2.0.0
|
|
3962
|
+
*/
|
|
3963
|
+
exports.foldMap = RA.foldMap;
|
|
3964
|
+
/**
|
|
3965
|
+
* Same as [`foldMap`](#foldMap) but passing also the index to the iterating function.
|
|
3966
|
+
*
|
|
3967
|
+
* @example
|
|
3968
|
+
* import { foldMapWithIndex } from 'fp-ts/Array'
|
|
3969
|
+
*
|
|
3970
|
+
* const monoid = { concat: (a: string, b: string) => a + b, empty: "" };
|
|
3971
|
+
* const f = (index:number, s: string) => `${s.toUpperCase()}(${index})`
|
|
3972
|
+
* assert.deepStrictEqual(foldMapWithIndex(monoid)(f)(["a", "b", "c"]), "A(0)B(1)C(2)");
|
|
3973
|
+
*
|
|
3974
|
+
* @category FoldableWithIndex
|
|
3975
|
+
* @since 2.0.0
|
|
3976
|
+
*/
|
|
3977
|
+
exports.foldMapWithIndex = RA.foldMapWithIndex;
|
|
3978
|
+
/**
|
|
3979
|
+
* Reduces an `Array`.
|
|
3980
|
+
*
|
|
3981
|
+
* `reduce` executes the supplied iterating function on each element of the array,
|
|
3982
|
+
* in order, passing in the element and the return value from the calculation on the preceding element.
|
|
3983
|
+
*
|
|
3984
|
+
* The first time that the iterating function is called there is no "return value of the
|
|
3985
|
+
* previous calculation", the initial value is used in its place.
|
|
3986
|
+
*
|
|
3987
|
+
* @example
|
|
3988
|
+
* import { reduce } from 'fp-ts/Array'
|
|
3989
|
+
*
|
|
3990
|
+
* assert.deepStrictEqual(reduce(5, (acc: number, cur: number) => acc * cur)([2, 3]), 5 * 2 * 3);
|
|
3991
|
+
*
|
|
3992
|
+
* @category Foldable
|
|
3993
|
+
* @since 2.0.0
|
|
3994
|
+
*/
|
|
3995
|
+
exports.reduce = RA.reduce;
|
|
3996
|
+
/**
|
|
3997
|
+
* Same as [`reduce`](#reduce) but passing also the index to the iterating function.
|
|
3998
|
+
*
|
|
3999
|
+
* @example
|
|
4000
|
+
* import { reduceWithIndex } from 'fp-ts/Array'
|
|
4001
|
+
*
|
|
4002
|
+
* const f = (index: number, acc: string, cur: unknown) =>
|
|
4003
|
+
* acc + (typeof cur === "string" ? cur.toUpperCase() + index : "");
|
|
4004
|
+
* assert.deepStrictEqual(reduceWithIndex("", f)([2, "a", "b", null]), "A1B2");
|
|
4005
|
+
*
|
|
4006
|
+
* @category FoldableWithIndex
|
|
4007
|
+
* @since 2.0.0
|
|
4008
|
+
*/
|
|
4009
|
+
exports.reduceWithIndex = RA.reduceWithIndex;
|
|
4010
|
+
/**
|
|
4011
|
+
* Same as [`reduce`](#reduce) but applied from the end to the start.
|
|
4012
|
+
*
|
|
4013
|
+
* *Note*: the iterating function in this case takes the accumulator as the last argument.
|
|
4014
|
+
*
|
|
4015
|
+
* @example
|
|
4016
|
+
* import { reduceRight } from 'fp-ts/Array'
|
|
4017
|
+
*
|
|
4018
|
+
* assert.deepStrictEqual(reduceRight("", (cur: string, acc: string) => acc + cur)(["a", "b", "c"]), "cba");
|
|
4019
|
+
*
|
|
4020
|
+
* @category Foldable
|
|
4021
|
+
* @since 2.0.0
|
|
4022
|
+
*/
|
|
4023
|
+
exports.reduceRight = RA.reduceRight;
|
|
4024
|
+
/**
|
|
4025
|
+
* Same as [`reduceRight`](#reduceRight) but passing also the index to the iterating function.
|
|
4026
|
+
*
|
|
4027
|
+
* @example
|
|
4028
|
+
* import { reduceRightWithIndex } from 'fp-ts/Array'
|
|
4029
|
+
*
|
|
4030
|
+
* const f = (index: number, cur: unknown, acc: string) =>
|
|
4031
|
+
* acc + (typeof cur === "string" ? cur.toUpperCase() + index : "");
|
|
4032
|
+
* assert.deepStrictEqual(reduceRightWithIndex("", f)([2, "a", "b", null]), "B2A1");
|
|
4033
|
+
*
|
|
4034
|
+
* @category FoldableWithIndex
|
|
4035
|
+
* @since 2.0.0
|
|
4036
|
+
*/
|
|
4037
|
+
exports.reduceRightWithIndex = RA.reduceRightWithIndex;
|
|
4038
|
+
/**
|
|
4039
|
+
* Given an iterating function that returns a `HKT` (higher kinded type), `traverse`
|
|
4040
|
+
* applies the iterating function to each element of the `Array` and then [`sequence`](#sequence)-s
|
|
4041
|
+
* the results using the provided `Applicative`.
|
|
4042
|
+
*
|
|
4043
|
+
* E.g. suppose you have an `Array` and you want to format each element with a function
|
|
4044
|
+
* that returns a result or an error as `f = (a: A) => Either<Error, B>`, using `traverse`
|
|
4045
|
+
* you can apply `f` to all elements and directly obtain as a result an `Either<Error,Array<B>>`
|
|
4046
|
+
* i.e. an `Array<B>` if all the results are `B`, or an `Error` if some of the results
|
|
4047
|
+
* are `Error`s.
|
|
4048
|
+
*
|
|
4049
|
+
* @example
|
|
4050
|
+
* import { traverse } from 'fp-ts/Array'
|
|
4051
|
+
* import { Applicative, left, right } from "fp-ts/lib/Either";
|
|
4052
|
+
*
|
|
4053
|
+
* const f = (x: unknown) =>
|
|
4054
|
+
* typeof x === "string" ? right(x.toUpperCase()) : left(new Error("not a string"));
|
|
4055
|
+
* assert.deepStrictEqual(traverse(Applicative)(f)(["a", "b"]), right(["A", "B"]));
|
|
4056
|
+
* assert.deepStrictEqual(traverse(Applicative)(f)(["a", 5]), left(new Error("not a string")));
|
|
4057
|
+
*
|
|
4058
|
+
* @category Traversable
|
|
4059
|
+
* @since 2.6.3
|
|
4060
|
+
*/
|
|
4061
|
+
var traverse = function (F) {
|
|
4062
|
+
var traverseWithIndexF = (0, exports.traverseWithIndex)(F);
|
|
4063
|
+
return function (f) { return traverseWithIndexF(function (_, a) { return f(a); }); };
|
|
4064
|
+
};
|
|
4065
|
+
exports.traverse = traverse;
|
|
4066
|
+
/**
|
|
4067
|
+
* `sequence` takes an `Array` where elements are `HKT<A>` (higher kinded type) and,
|
|
4068
|
+
* using an applicative of that `HKT`, returns an `HKT` of `Array<A>`.
|
|
4069
|
+
* E.g. it can turn an `Array<Either<Error, string>>` into an `Either<Error, Array<string>>`.
|
|
4070
|
+
*
|
|
4071
|
+
* `sequence` requires an `Applicative` of the `HKT` you are targeting, e.g. to turn an
|
|
4072
|
+
* `Array<Either<E, A>>` into an `Either<E, Array<A>>`, it needs an
|
|
4073
|
+
* `Applicative` for `Either`, to to turn an `Array<Option<A>>` into an `Option<Array<A>>`,
|
|
4074
|
+
* it needs an `Applicative` for `Option`.
|
|
4075
|
+
*
|
|
4076
|
+
* @example
|
|
4077
|
+
* import { sequence } from 'fp-ts/Array'
|
|
4078
|
+
* import { Applicative, left, right } from "fp-ts/lib/Either";
|
|
4079
|
+
*
|
|
4080
|
+
* assert.deepStrictEqual(sequence(Applicative)([right("a"), right("b")]), right(["a", "b"]));
|
|
4081
|
+
* assert.deepStrictEqual(
|
|
4082
|
+
* sequence(Applicative)([right("a"), left(new Error("not a string"))]),
|
|
4083
|
+
* left(new Error("not a string"))
|
|
4084
|
+
* );
|
|
4085
|
+
*
|
|
4086
|
+
* @category Traversable
|
|
4087
|
+
* @since 2.6.3
|
|
4088
|
+
*/
|
|
4089
|
+
var sequence = function (F) { return function (ta) {
|
|
4090
|
+
return _reduce(ta, F.of((0, exports.zero)()), function (fas, fa) {
|
|
4091
|
+
return F.ap(F.map(fas, function (as) { return function (a) { return (0, _function.pipe)(as, (0, exports.append)(a)); }; }), fa);
|
|
4092
|
+
});
|
|
4093
|
+
}; };
|
|
4094
|
+
exports.sequence = sequence;
|
|
4095
|
+
/**
|
|
4096
|
+
* Same as [`traverse`](#traverse) but passing also the index to the iterating function.
|
|
4097
|
+
*
|
|
4098
|
+
* @example
|
|
4099
|
+
* import { traverseWithIndex } from 'fp-ts/Array'
|
|
4100
|
+
* import { Applicative, left, right } from "fp-ts/lib/Either";
|
|
4101
|
+
*
|
|
4102
|
+
* const f = (index:number, x:unknown) =>
|
|
4103
|
+
* typeof x === "string" ? right(x.toUpperCase() + index) : left(new Error("not a string"));
|
|
4104
|
+
* assert.deepStrictEqual(traverseWithIndex(Applicative)(f)(["a", "b"]), right(["A0", "B1"]));
|
|
4105
|
+
* assert.deepStrictEqual(traverseWithIndex(Applicative)(f)(["a", 5]), left(new Error("not a string")));
|
|
4106
|
+
*
|
|
4107
|
+
* @category TraversableWithIndex
|
|
4108
|
+
* @since 2.6.3
|
|
4109
|
+
*/
|
|
4110
|
+
var traverseWithIndex = function (F) { return function (f) {
|
|
4111
|
+
return (0, exports.reduceWithIndex)(F.of((0, exports.zero)()), function (i, fbs, a) {
|
|
4112
|
+
return F.ap(F.map(fbs, function (bs) { return function (b) { return (0, _function.pipe)(bs, (0, exports.append)(b)); }; }), f(i, a));
|
|
4113
|
+
});
|
|
4114
|
+
}; };
|
|
4115
|
+
exports.traverseWithIndex = traverseWithIndex;
|
|
4116
|
+
/**
|
|
4117
|
+
* @category Witherable
|
|
4118
|
+
* @since 2.6.5
|
|
4119
|
+
*/
|
|
4120
|
+
var wither = function (F) {
|
|
4121
|
+
var _witherF = _wither(F);
|
|
4122
|
+
return function (f) { return function (fa) { return _witherF(fa, f); }; };
|
|
4123
|
+
};
|
|
4124
|
+
exports.wither = wither;
|
|
4125
|
+
/**
|
|
4126
|
+
* @category Witherable
|
|
4127
|
+
* @since 2.6.5
|
|
4128
|
+
*/
|
|
4129
|
+
var wilt = function (F) {
|
|
4130
|
+
var _wiltF = _wilt(F);
|
|
4131
|
+
return function (f) { return function (fa) { return _wiltF(fa, f); }; };
|
|
4132
|
+
};
|
|
4133
|
+
exports.wilt = wilt;
|
|
4134
|
+
/**
|
|
4135
|
+
* `unfold` takes a function `f` which returns an `Option` of a tuple containing an outcome
|
|
4136
|
+
* value and an input for the following iteration.
|
|
4137
|
+
* `unfold` applies `f` to the initial value `b` and then recursively to the second
|
|
4138
|
+
* element of the tuple contained in the returned `option` of the previous
|
|
4139
|
+
* calculation until `f` returns `Option.none`.
|
|
4140
|
+
*
|
|
4141
|
+
* @example
|
|
4142
|
+
* import { unfold } from 'fp-ts/Array'
|
|
4143
|
+
* import { option } from 'fp-ts'
|
|
4144
|
+
*
|
|
4145
|
+
* const f = (n: number) => {
|
|
4146
|
+
* if (n <= 0) return option.none;
|
|
4147
|
+
* const returnValue = n * 2;
|
|
4148
|
+
* const inputForNextRound = n - 1;
|
|
4149
|
+
* return option.some([returnValue, inputForNextRound] as const);
|
|
4150
|
+
* };
|
|
4151
|
+
* assert.deepStrictEqual(unfold(5, f), [10, 8, 6, 4, 2]);
|
|
4152
|
+
*
|
|
4153
|
+
* @category Unfoldable
|
|
4154
|
+
* @since 2.6.6
|
|
4155
|
+
*/
|
|
4156
|
+
var unfold = function (b, f) {
|
|
4157
|
+
var out = [];
|
|
4158
|
+
var bb = b;
|
|
4159
|
+
// eslint-disable-next-line no-constant-condition
|
|
4160
|
+
while (true) {
|
|
4161
|
+
var mt = f(bb);
|
|
4162
|
+
if (_.isSome(mt)) {
|
|
4163
|
+
var _a = mt.value, a = _a[0], b_1 = _a[1];
|
|
4164
|
+
out.push(a);
|
|
4165
|
+
bb = b_1;
|
|
4166
|
+
}
|
|
4167
|
+
else {
|
|
4168
|
+
break;
|
|
4169
|
+
}
|
|
4170
|
+
}
|
|
4171
|
+
return out;
|
|
4172
|
+
};
|
|
4173
|
+
exports.unfold = unfold;
|
|
4174
|
+
// -------------------------------------------------------------------------------------
|
|
4175
|
+
// instances
|
|
4176
|
+
// -------------------------------------------------------------------------------------
|
|
4177
|
+
/**
|
|
4178
|
+
* @category instances
|
|
4179
|
+
* @since 2.0.0
|
|
4180
|
+
*/
|
|
4181
|
+
exports.URI = 'Array';
|
|
4182
|
+
/**
|
|
4183
|
+
* `getShow` makes a `Show` for an `Array<A>` from a `Show` for
|
|
4184
|
+
* an `A`.
|
|
4185
|
+
*
|
|
4186
|
+
* @example
|
|
4187
|
+
* import { getShow } from 'fp-ts/Array'
|
|
4188
|
+
*
|
|
4189
|
+
* const numShow = { show: (n: number) => (n >= 0 ? `${n}` : `(${-n})`) };
|
|
4190
|
+
* assert.deepStrictEqual(getShow(numShow).show([-2, -1, 0, 1]), "[(2), (1), 0, 1]");
|
|
4191
|
+
*
|
|
4192
|
+
* @category instances
|
|
4193
|
+
* @since 2.0.0
|
|
4194
|
+
*/
|
|
4195
|
+
exports.getShow = RA.getShow;
|
|
4196
|
+
/**
|
|
4197
|
+
* Get a `Semigroup` based on the concatenation of `Array`s.
|
|
4198
|
+
* See also [`getMonoid`](#getMonoid).
|
|
4199
|
+
*
|
|
4200
|
+
* @example
|
|
4201
|
+
* import { getSemigroup } from 'fp-ts/Array'
|
|
4202
|
+
*
|
|
4203
|
+
* const S = getSemigroup<number>();
|
|
4204
|
+
* assert.deepStrictEqual(S.concat([1, 2], [2, 3]), [1, 2, 2, 3]);
|
|
4205
|
+
*
|
|
4206
|
+
* @category instances
|
|
4207
|
+
* @since 2.10.0
|
|
4208
|
+
*/
|
|
4209
|
+
var getSemigroup = function () { return ({
|
|
4210
|
+
concat: function (first, second) { return first.concat(second); }
|
|
4211
|
+
}); };
|
|
4212
|
+
exports.getSemigroup = getSemigroup;
|
|
4213
|
+
/**
|
|
4214
|
+
* Returns a `Monoid` for `Array<A>` based on the concatenation of `Array`s.
|
|
4215
|
+
*
|
|
4216
|
+
* @example
|
|
4217
|
+
* import { getMonoid } from 'fp-ts/Array'
|
|
4218
|
+
*
|
|
4219
|
+
* const M = getMonoid<number>()
|
|
4220
|
+
* assert.deepStrictEqual(M.concat([1, 2], [3, 4]), [1, 2, 3, 4])
|
|
4221
|
+
*
|
|
4222
|
+
* @category instances
|
|
4223
|
+
* @since 2.0.0
|
|
4224
|
+
*/
|
|
4225
|
+
var getMonoid = function () { return ({
|
|
4226
|
+
concat: (0, exports.getSemigroup)().concat,
|
|
4227
|
+
empty: []
|
|
4228
|
+
}); };
|
|
4229
|
+
exports.getMonoid = getMonoid;
|
|
4230
|
+
/**
|
|
4231
|
+
* Derives an `Eq` over the `Array` of a given element type from the `Eq` of that type. The derived `Eq` defines two
|
|
4232
|
+
* arrays as equal if all elements of both arrays are compared equal pairwise with the given `E`. In case of arrays of
|
|
4233
|
+
* different lengths, the result is non equality.
|
|
4234
|
+
*
|
|
4235
|
+
* @example
|
|
4236
|
+
* import * as S from 'fp-ts/string'
|
|
4237
|
+
* import { getEq } from 'fp-ts/Array'
|
|
4238
|
+
*
|
|
4239
|
+
* const E = getEq(S.Eq)
|
|
4240
|
+
* assert.strictEqual(E.equals(['a', 'b'], ['a', 'b']), true)
|
|
4241
|
+
* assert.strictEqual(E.equals(['a'], []), false)
|
|
4242
|
+
*
|
|
4243
|
+
* @category instances
|
|
4244
|
+
* @since 2.0.0
|
|
4245
|
+
*/
|
|
4246
|
+
exports.getEq = RA.getEq;
|
|
4247
|
+
/**
|
|
4248
|
+
* Derives an `Ord` over the `Array` of a given element type from the `Ord` of that type. The ordering between two such
|
|
4249
|
+
* arrays is equal to: the first non equal comparison of each arrays elements taken pairwise in increasing order, in
|
|
4250
|
+
* case of equality over all the pairwise elements; the longest array is considered the greatest, if both arrays have
|
|
4251
|
+
* the same length, the result is equality.
|
|
4252
|
+
*
|
|
4253
|
+
* @example
|
|
4254
|
+
* import { getOrd } from 'fp-ts/Array'
|
|
4255
|
+
* import * as S from 'fp-ts/string'
|
|
4256
|
+
*
|
|
4257
|
+
* const O = getOrd(S.Ord)
|
|
4258
|
+
* assert.strictEqual(O.compare(['b'], ['a']), 1)
|
|
4259
|
+
* assert.strictEqual(O.compare(['a'], ['a']), 0)
|
|
4260
|
+
* assert.strictEqual(O.compare(['a'], ['b']), -1)
|
|
4261
|
+
*
|
|
4262
|
+
* @category instances
|
|
4263
|
+
* @since 2.0.0
|
|
4264
|
+
*/
|
|
4265
|
+
exports.getOrd = RA.getOrd;
|
|
4266
|
+
/**
|
|
4267
|
+
* Get a `Semigroup` based on the union of the elements of `Array`s.
|
|
4268
|
+
* Elements which equal according to the provided `Eq` are included
|
|
4269
|
+
* only once in the result.
|
|
4270
|
+
* See also [`getUnionMonoid`](#getUnionMonoid).
|
|
4271
|
+
*
|
|
4272
|
+
* @example
|
|
4273
|
+
* import { getUnionSemigroup } from 'fp-ts/Array';
|
|
4274
|
+
* import { Eq } from 'fp-ts/number';
|
|
4275
|
+
*
|
|
4276
|
+
* const S = getUnionSemigroup<number>(Eq);
|
|
4277
|
+
* assert.deepStrictEqual(S.concat([1, 2], [2, 3]), [1, 2, 3]);
|
|
4278
|
+
*
|
|
4279
|
+
* @category instances
|
|
4280
|
+
* @since 2.11.0
|
|
4281
|
+
*/
|
|
4282
|
+
var getUnionSemigroup = function (E) {
|
|
4283
|
+
var unionE = union(E);
|
|
4284
|
+
return {
|
|
4285
|
+
concat: function (first, second) { return unionE(second)(first); }
|
|
4286
|
+
};
|
|
4287
|
+
};
|
|
4288
|
+
exports.getUnionSemigroup = getUnionSemigroup;
|
|
4289
|
+
/**
|
|
4290
|
+
* Get a `Monoid` based on the union of the elements of `Array`s.
|
|
4291
|
+
* Elements which equal according to the provided `Eq` are included
|
|
4292
|
+
* only once in the result.
|
|
4293
|
+
*
|
|
4294
|
+
* @example
|
|
4295
|
+
* import { getUnionMonoid } from 'fp-ts/Array'
|
|
4296
|
+
* import { Eq } from 'fp-ts/number';
|
|
4297
|
+
*
|
|
4298
|
+
* const M = getUnionMonoid<number>(Eq);
|
|
4299
|
+
* assert.deepStrictEqual(M.concat([1, 2], [2, 3]), [1, 2, 3]);
|
|
4300
|
+
* assert.deepStrictEqual(M.empty,[]);
|
|
4301
|
+
*
|
|
4302
|
+
* @category instances
|
|
4303
|
+
* @since 2.11.0
|
|
4304
|
+
*/
|
|
4305
|
+
var getUnionMonoid = function (E) { return ({
|
|
4306
|
+
concat: (0, exports.getUnionSemigroup)(E).concat,
|
|
4307
|
+
empty: []
|
|
4308
|
+
}); };
|
|
4309
|
+
exports.getUnionMonoid = getUnionMonoid;
|
|
4310
|
+
/**
|
|
4311
|
+
* Get a `Semigroup` based on the intersection of the elements of `Array`s.
|
|
4312
|
+
* Only elements present in the two arrays which are equal according to the
|
|
4313
|
+
* provided `Eq` are included in the result.
|
|
4314
|
+
*
|
|
4315
|
+
* @example
|
|
4316
|
+
* import { getIntersectionSemigroup } from 'fp-ts/Array'
|
|
4317
|
+
* import { Eq } from 'fp-ts/number';
|
|
4318
|
+
*
|
|
4319
|
+
* const S = getIntersectionSemigroup<number>(Eq);
|
|
4320
|
+
* assert.deepStrictEqual(S.concat([1, 2], [2, 3]), [2]);
|
|
4321
|
+
*
|
|
4322
|
+
* @category instances
|
|
4323
|
+
* @since 2.11.0
|
|
4324
|
+
*/
|
|
4325
|
+
var getIntersectionSemigroup = function (E) {
|
|
4326
|
+
var intersectionE = intersection(E);
|
|
4327
|
+
return {
|
|
4328
|
+
concat: function (first, second) { return intersectionE(second)(first); }
|
|
4329
|
+
};
|
|
4330
|
+
};
|
|
4331
|
+
exports.getIntersectionSemigroup = getIntersectionSemigroup;
|
|
4332
|
+
/**
|
|
4333
|
+
* Get a `Magma` for `Array` where the `concat` function is the differnce between
|
|
4334
|
+
* the first and the second array, i.e. the result contains all the elements of the
|
|
4335
|
+
* first array for which their is no equal element in the second array according
|
|
4336
|
+
* to the `Eq` provided.
|
|
4337
|
+
*
|
|
4338
|
+
*
|
|
4339
|
+
* @example
|
|
4340
|
+
* import { getDifferenceMagma } from 'fp-ts/Array'
|
|
4341
|
+
* import { Eq } from 'fp-ts/number';
|
|
4342
|
+
*
|
|
4343
|
+
* const S = getDifferenceMagma<number>(Eq);
|
|
4344
|
+
* assert.deepStrictEqual(S.concat([1, 2], [2, 3]), [1]);
|
|
4345
|
+
*
|
|
4346
|
+
* @category instances
|
|
4347
|
+
* @since 2.11.0
|
|
4348
|
+
*/
|
|
4349
|
+
var getDifferenceMagma = function (E) {
|
|
4350
|
+
var differenceE = difference(E);
|
|
4351
|
+
return {
|
|
4352
|
+
concat: function (first, second) { return differenceE(second)(first); }
|
|
4353
|
+
};
|
|
4354
|
+
};
|
|
4355
|
+
exports.getDifferenceMagma = getDifferenceMagma;
|
|
4356
|
+
/**
|
|
4357
|
+
* @category instances
|
|
4358
|
+
* @since 2.7.0
|
|
4359
|
+
*/
|
|
4360
|
+
exports.Functor = {
|
|
4361
|
+
URI: exports.URI,
|
|
4362
|
+
map: _map
|
|
4363
|
+
};
|
|
4364
|
+
/**
|
|
4365
|
+
* Given an input an `Array` of functions, `flap` returns an `Array` containing
|
|
4366
|
+
* the results of applying each function to the given input.
|
|
4367
|
+
*
|
|
4368
|
+
* @example
|
|
4369
|
+
* import { flap } from 'fp-ts/Array'
|
|
4370
|
+
*
|
|
4371
|
+
* const funs = [
|
|
4372
|
+
* (n: number) => `Double: ${n * 2}`,
|
|
4373
|
+
* (n: number) => `Triple: ${n * 3}`,
|
|
4374
|
+
* (n: number) => `Square: ${n * n}`,
|
|
4375
|
+
* ];
|
|
4376
|
+
* assert.deepStrictEqual(flap(4)(funs), ['Double: 8', 'Triple: 12', 'Square: 16']);
|
|
4377
|
+
*
|
|
4378
|
+
* @category combinators
|
|
4379
|
+
* @since 2.10.0
|
|
4380
|
+
*/
|
|
4381
|
+
exports.flap = (0, Functor.flap)(exports.Functor);
|
|
4382
|
+
/**
|
|
4383
|
+
* @category instances
|
|
4384
|
+
* @since 2.10.0
|
|
4385
|
+
*/
|
|
4386
|
+
exports.Pointed = {
|
|
4387
|
+
URI: exports.URI,
|
|
4388
|
+
of: exports.of
|
|
4389
|
+
};
|
|
4390
|
+
/**
|
|
4391
|
+
* @category instances
|
|
4392
|
+
* @since 2.7.0
|
|
4393
|
+
*/
|
|
4394
|
+
exports.FunctorWithIndex = {
|
|
4395
|
+
URI: exports.URI,
|
|
4396
|
+
map: _map,
|
|
4397
|
+
mapWithIndex: _mapWithIndex
|
|
4398
|
+
};
|
|
4399
|
+
/**
|
|
4400
|
+
* @category instances
|
|
4401
|
+
* @since 2.10.0
|
|
4402
|
+
*/
|
|
4403
|
+
exports.Apply = {
|
|
4404
|
+
URI: exports.URI,
|
|
4405
|
+
map: _map,
|
|
4406
|
+
ap: _ap
|
|
4407
|
+
};
|
|
4408
|
+
/**
|
|
4409
|
+
* Combine two effectful actions, keeping only the result of the first.
|
|
4410
|
+
*
|
|
4411
|
+
* Derivable from `Apply`.
|
|
4412
|
+
*
|
|
4413
|
+
* @category combinators
|
|
4414
|
+
* @since 2.5.0
|
|
4415
|
+
*/
|
|
4416
|
+
exports.apFirst = (0, Apply.apFirst)(exports.Apply);
|
|
4417
|
+
/**
|
|
4418
|
+
* Combine two effectful actions, keeping only the result of the second.
|
|
4419
|
+
*
|
|
4420
|
+
* Derivable from `Apply`.
|
|
4421
|
+
*
|
|
4422
|
+
* @category combinators
|
|
4423
|
+
* @since 2.5.0
|
|
4424
|
+
*/
|
|
4425
|
+
exports.apSecond = (0, Apply.apSecond)(exports.Apply);
|
|
4426
|
+
/**
|
|
4427
|
+
* @category instances
|
|
4428
|
+
* @since 2.7.0
|
|
4429
|
+
*/
|
|
4430
|
+
exports.Applicative = {
|
|
4431
|
+
URI: exports.URI,
|
|
4432
|
+
map: _map,
|
|
4433
|
+
ap: _ap,
|
|
4434
|
+
of: exports.of
|
|
4435
|
+
};
|
|
4436
|
+
/**
|
|
4437
|
+
* @category instances
|
|
4438
|
+
* @since 2.10.0
|
|
4439
|
+
*/
|
|
4440
|
+
exports.Chain = {
|
|
4441
|
+
URI: exports.URI,
|
|
4442
|
+
map: _map,
|
|
4443
|
+
ap: _ap,
|
|
4444
|
+
chain: _chain
|
|
4445
|
+
};
|
|
4446
|
+
/**
|
|
4447
|
+
* Composes computations in sequence, using the return value of one computation to determine the next computation and
|
|
4448
|
+
* keeping only the result of the first.
|
|
4449
|
+
*
|
|
4450
|
+
* Derivable from `Chain`.
|
|
4451
|
+
*
|
|
4452
|
+
* @category combinators
|
|
4453
|
+
* @since 2.0.0
|
|
4454
|
+
*/
|
|
4455
|
+
exports.chainFirst = (0, Chain.chainFirst)(exports.Chain);
|
|
4456
|
+
/**
|
|
4457
|
+
* @category instances
|
|
4458
|
+
* @since 2.7.0
|
|
4459
|
+
*/
|
|
4460
|
+
exports.Monad = {
|
|
4461
|
+
URI: exports.URI,
|
|
4462
|
+
map: _map,
|
|
4463
|
+
ap: _ap,
|
|
4464
|
+
of: exports.of,
|
|
4465
|
+
chain: _chain
|
|
4466
|
+
};
|
|
4467
|
+
/**
|
|
4468
|
+
* @category instances
|
|
4469
|
+
* @since 2.7.0
|
|
4470
|
+
*/
|
|
4471
|
+
exports.Unfoldable = {
|
|
4472
|
+
URI: exports.URI,
|
|
4473
|
+
unfold: exports.unfold
|
|
4474
|
+
};
|
|
4475
|
+
/**
|
|
4476
|
+
* @category instances
|
|
4477
|
+
* @since 2.7.0
|
|
4478
|
+
*/
|
|
4479
|
+
exports.Alt = {
|
|
4480
|
+
URI: exports.URI,
|
|
4481
|
+
map: _map,
|
|
4482
|
+
alt: _alt
|
|
4483
|
+
};
|
|
4484
|
+
/**
|
|
4485
|
+
* @category instances
|
|
4486
|
+
* @since 2.11.0
|
|
4487
|
+
*/
|
|
4488
|
+
exports.Zero = {
|
|
4489
|
+
URI: exports.URI,
|
|
4490
|
+
zero: exports.zero
|
|
4491
|
+
};
|
|
4492
|
+
/**
|
|
4493
|
+
* @category constructors
|
|
4494
|
+
* @since 2.11.0
|
|
4495
|
+
*/
|
|
4496
|
+
exports.guard = (0, Zero.guard)(exports.Zero, exports.Pointed);
|
|
4497
|
+
/**
|
|
4498
|
+
* @category instances
|
|
4499
|
+
* @since 2.7.0
|
|
4500
|
+
*/
|
|
4501
|
+
exports.Alternative = {
|
|
4502
|
+
URI: exports.URI,
|
|
4503
|
+
map: _map,
|
|
4504
|
+
ap: _ap,
|
|
4505
|
+
of: exports.of,
|
|
4506
|
+
alt: _alt,
|
|
4507
|
+
zero: exports.zero
|
|
4508
|
+
};
|
|
4509
|
+
/**
|
|
4510
|
+
* @category instances
|
|
4511
|
+
* @since 2.7.0
|
|
4512
|
+
*/
|
|
4513
|
+
exports.Extend = {
|
|
4514
|
+
URI: exports.URI,
|
|
4515
|
+
map: _map,
|
|
4516
|
+
extend: _extend
|
|
4517
|
+
};
|
|
4518
|
+
/**
|
|
4519
|
+
* @category instances
|
|
4520
|
+
* @since 2.7.0
|
|
4521
|
+
*/
|
|
4522
|
+
exports.Compactable = {
|
|
4523
|
+
URI: exports.URI,
|
|
4524
|
+
compact: exports.compact,
|
|
4525
|
+
separate: exports.separate
|
|
4526
|
+
};
|
|
4527
|
+
/**
|
|
4528
|
+
* @category instances
|
|
4529
|
+
* @since 2.7.0
|
|
4530
|
+
*/
|
|
4531
|
+
exports.Filterable = {
|
|
4532
|
+
URI: exports.URI,
|
|
4533
|
+
map: _map,
|
|
4534
|
+
compact: exports.compact,
|
|
4535
|
+
separate: exports.separate,
|
|
4536
|
+
filter: _filter,
|
|
4537
|
+
filterMap: _filterMap,
|
|
4538
|
+
partition: _partition,
|
|
4539
|
+
partitionMap: _partitionMap
|
|
4540
|
+
};
|
|
4541
|
+
/**
|
|
4542
|
+
* @category instances
|
|
4543
|
+
* @since 2.7.0
|
|
4544
|
+
*/
|
|
4545
|
+
exports.FilterableWithIndex = {
|
|
4546
|
+
URI: exports.URI,
|
|
4547
|
+
map: _map,
|
|
4548
|
+
mapWithIndex: _mapWithIndex,
|
|
4549
|
+
compact: exports.compact,
|
|
4550
|
+
separate: exports.separate,
|
|
4551
|
+
filter: _filter,
|
|
4552
|
+
filterMap: _filterMap,
|
|
4553
|
+
partition: _partition,
|
|
4554
|
+
partitionMap: _partitionMap,
|
|
4555
|
+
partitionMapWithIndex: _partitionMapWithIndex,
|
|
4556
|
+
partitionWithIndex: _partitionWithIndex,
|
|
4557
|
+
filterMapWithIndex: _filterMapWithIndex,
|
|
4558
|
+
filterWithIndex: _filterWithIndex
|
|
4559
|
+
};
|
|
4560
|
+
/**
|
|
4561
|
+
* @category instances
|
|
4562
|
+
* @since 2.7.0
|
|
4563
|
+
*/
|
|
4564
|
+
exports.Foldable = {
|
|
4565
|
+
URI: exports.URI,
|
|
4566
|
+
reduce: _reduce,
|
|
4567
|
+
foldMap: _foldMap,
|
|
4568
|
+
reduceRight: _reduceRight
|
|
4569
|
+
};
|
|
4570
|
+
/**
|
|
4571
|
+
* @category instances
|
|
4572
|
+
* @since 2.7.0
|
|
4573
|
+
*/
|
|
4574
|
+
exports.FoldableWithIndex = {
|
|
4575
|
+
URI: exports.URI,
|
|
4576
|
+
reduce: _reduce,
|
|
4577
|
+
foldMap: _foldMap,
|
|
4578
|
+
reduceRight: _reduceRight,
|
|
4579
|
+
reduceWithIndex: _reduceWithIndex,
|
|
4580
|
+
foldMapWithIndex: _foldMapWithIndex,
|
|
4581
|
+
reduceRightWithIndex: _reduceRightWithIndex
|
|
4582
|
+
};
|
|
4583
|
+
/**
|
|
4584
|
+
* @category instances
|
|
4585
|
+
* @since 2.7.0
|
|
4586
|
+
*/
|
|
4587
|
+
exports.Traversable = {
|
|
4588
|
+
URI: exports.URI,
|
|
4589
|
+
map: _map,
|
|
4590
|
+
reduce: _reduce,
|
|
4591
|
+
foldMap: _foldMap,
|
|
4592
|
+
reduceRight: _reduceRight,
|
|
4593
|
+
traverse: _traverse,
|
|
4594
|
+
sequence: exports.sequence
|
|
4595
|
+
};
|
|
4596
|
+
/**
|
|
4597
|
+
* @category instances
|
|
4598
|
+
* @since 2.7.0
|
|
4599
|
+
*/
|
|
4600
|
+
exports.TraversableWithIndex = {
|
|
4601
|
+
URI: exports.URI,
|
|
4602
|
+
map: _map,
|
|
4603
|
+
mapWithIndex: _mapWithIndex,
|
|
4604
|
+
reduce: _reduce,
|
|
4605
|
+
foldMap: _foldMap,
|
|
4606
|
+
reduceRight: _reduceRight,
|
|
4607
|
+
reduceWithIndex: _reduceWithIndex,
|
|
4608
|
+
foldMapWithIndex: _foldMapWithIndex,
|
|
4609
|
+
reduceRightWithIndex: _reduceRightWithIndex,
|
|
4610
|
+
traverse: _traverse,
|
|
4611
|
+
sequence: exports.sequence,
|
|
4612
|
+
traverseWithIndex: _traverseWithIndex
|
|
4613
|
+
};
|
|
4614
|
+
var _wither = /*#__PURE__*/ (0, Witherable.witherDefault)(exports.Traversable, exports.Compactable);
|
|
4615
|
+
var _wilt = /*#__PURE__*/ (0, Witherable.wiltDefault)(exports.Traversable, exports.Compactable);
|
|
4616
|
+
/**
|
|
4617
|
+
* @category instances
|
|
4618
|
+
* @since 2.7.0
|
|
4619
|
+
*/
|
|
4620
|
+
exports.Witherable = {
|
|
4621
|
+
URI: exports.URI,
|
|
4622
|
+
map: _map,
|
|
4623
|
+
compact: exports.compact,
|
|
4624
|
+
separate: exports.separate,
|
|
4625
|
+
filter: _filter,
|
|
4626
|
+
filterMap: _filterMap,
|
|
4627
|
+
partition: _partition,
|
|
4628
|
+
partitionMap: _partitionMap,
|
|
4629
|
+
reduce: _reduce,
|
|
4630
|
+
foldMap: _foldMap,
|
|
4631
|
+
reduceRight: _reduceRight,
|
|
4632
|
+
traverse: _traverse,
|
|
4633
|
+
sequence: exports.sequence,
|
|
4634
|
+
wither: _wither,
|
|
4635
|
+
wilt: _wilt
|
|
4636
|
+
};
|
|
4637
|
+
/**
|
|
4638
|
+
* @category ChainRec
|
|
4639
|
+
* @since 2.11.0
|
|
4640
|
+
*/
|
|
4641
|
+
exports.chainRecDepthFirst = RA.chainRecDepthFirst;
|
|
4642
|
+
/**
|
|
4643
|
+
* @category instances
|
|
4644
|
+
* @since 2.11.0
|
|
4645
|
+
*/
|
|
4646
|
+
exports.ChainRecDepthFirst = {
|
|
4647
|
+
URI: exports.URI,
|
|
4648
|
+
map: _map,
|
|
4649
|
+
ap: _ap,
|
|
4650
|
+
chain: _chain,
|
|
4651
|
+
chainRec: _chainRecDepthFirst
|
|
4652
|
+
};
|
|
4653
|
+
/**
|
|
4654
|
+
* @category ChainRec
|
|
4655
|
+
* @since 2.11.0
|
|
4656
|
+
*/
|
|
4657
|
+
exports.chainRecBreadthFirst = RA.chainRecBreadthFirst;
|
|
4658
|
+
/**
|
|
4659
|
+
* @category instances
|
|
4660
|
+
* @since 2.11.0
|
|
4661
|
+
*/
|
|
4662
|
+
exports.ChainRecBreadthFirst = {
|
|
4663
|
+
URI: exports.URI,
|
|
4664
|
+
map: _map,
|
|
4665
|
+
ap: _ap,
|
|
4666
|
+
chain: _chain,
|
|
4667
|
+
chainRec: _chainRecBreadthFirst
|
|
4668
|
+
};
|
|
4669
|
+
/**
|
|
4670
|
+
* Filter values inside a context.
|
|
4671
|
+
*
|
|
4672
|
+
* @since 2.11.0
|
|
4673
|
+
*/
|
|
4674
|
+
exports.filterE = (0, Witherable.filterE)(exports.Witherable);
|
|
4675
|
+
/**
|
|
4676
|
+
* @category instances
|
|
4677
|
+
* @since 2.11.0
|
|
4678
|
+
*/
|
|
4679
|
+
exports.FromEither = {
|
|
4680
|
+
URI: exports.URI,
|
|
4681
|
+
fromEither: exports.fromEither
|
|
4682
|
+
};
|
|
4683
|
+
/**
|
|
4684
|
+
* @category combinators
|
|
4685
|
+
* @since 2.11.0
|
|
4686
|
+
*/
|
|
4687
|
+
exports.fromEitherK = (0, FromEither.fromEitherK)(exports.FromEither);
|
|
4688
|
+
// -------------------------------------------------------------------------------------
|
|
4689
|
+
// unsafe
|
|
4690
|
+
// -------------------------------------------------------------------------------------
|
|
4691
|
+
/**
|
|
4692
|
+
* @category unsafe
|
|
4693
|
+
* @since 2.0.0
|
|
4694
|
+
*/
|
|
4695
|
+
exports.unsafeInsertAt = NEA.unsafeInsertAt;
|
|
4696
|
+
/**
|
|
4697
|
+
* @category unsafe
|
|
4698
|
+
* @since 2.0.0
|
|
4699
|
+
*/
|
|
4700
|
+
var unsafeUpdateAt = function (i, a, as) {
|
|
4701
|
+
return (0, exports.isNonEmpty)(as) ? NEA.unsafeUpdateAt(i, a, as) : [];
|
|
4702
|
+
};
|
|
4703
|
+
exports.unsafeUpdateAt = unsafeUpdateAt;
|
|
4704
|
+
/**
|
|
4705
|
+
* @category unsafe
|
|
4706
|
+
* @since 2.0.0
|
|
4707
|
+
*/
|
|
4708
|
+
var unsafeDeleteAt = function (i, as) {
|
|
4709
|
+
var xs = as.slice();
|
|
4710
|
+
xs.splice(i, 1);
|
|
4711
|
+
return xs;
|
|
4712
|
+
};
|
|
4713
|
+
exports.unsafeDeleteAt = unsafeDeleteAt;
|
|
4714
|
+
// -------------------------------------------------------------------------------------
|
|
4715
|
+
// utils
|
|
4716
|
+
// -------------------------------------------------------------------------------------
|
|
4717
|
+
/**
|
|
4718
|
+
* `every` tells if the provided predicate holds true for every element in the `Array`.
|
|
4719
|
+
*
|
|
4720
|
+
* @example
|
|
4721
|
+
* import { every } from 'fp-ts/Array'
|
|
4722
|
+
*
|
|
4723
|
+
* assert.equal(every((x: number) => x >= 0)([1, 2, 3]), true);
|
|
4724
|
+
* assert.equal(every((x: number) => x >= 0)([-1, 2, 3]), false);
|
|
4725
|
+
*
|
|
4726
|
+
* @since 2.9.0
|
|
4727
|
+
*/
|
|
4728
|
+
exports.every = RA.every;
|
|
4729
|
+
/**
|
|
4730
|
+
* `some` tells if the provided predicate holds true at least for one element in the `Array`.
|
|
4731
|
+
*
|
|
4732
|
+
* @example
|
|
4733
|
+
* import { some } from 'fp-ts/Array'
|
|
4734
|
+
*
|
|
4735
|
+
* assert.equal(some((x: number) => x >= 0)([1, 2, 3]), true);
|
|
4736
|
+
* assert.equal(some((x: number) => x >= 10)([1, 2, 3]), false);
|
|
4737
|
+
*
|
|
4738
|
+
* @since 2.9.0
|
|
4739
|
+
*/
|
|
4740
|
+
var some = function (predicate) { return function (as) { return as.some(predicate); }; };
|
|
4741
|
+
exports.some = some;
|
|
4742
|
+
/**
|
|
4743
|
+
* Alias of [`some`](#some)
|
|
4744
|
+
*
|
|
4745
|
+
* @since 2.11.0
|
|
4746
|
+
*/
|
|
4747
|
+
exports.exists = exports.some;
|
|
4748
|
+
/**
|
|
4749
|
+
* Places an element in between members of an `Array`, then folds the results using the provided `Monoid`.
|
|
4750
|
+
*
|
|
4751
|
+
* @example
|
|
4752
|
+
* import * as S from 'fp-ts/string'
|
|
4753
|
+
* import { intercalate } from 'fp-ts/Array'
|
|
4754
|
+
*
|
|
4755
|
+
* assert.deepStrictEqual(intercalate(S.Monoid)('-')(['a', 'b', 'c']), 'a-b-c')
|
|
4756
|
+
*
|
|
4757
|
+
* @since 2.12.0
|
|
4758
|
+
*/
|
|
4759
|
+
exports.intercalate = RA.intercalate;
|
|
4760
|
+
// -------------------------------------------------------------------------------------
|
|
4761
|
+
// do notation
|
|
4762
|
+
// -------------------------------------------------------------------------------------
|
|
4763
|
+
/**
|
|
4764
|
+
* @since 2.9.0
|
|
4765
|
+
*/
|
|
4766
|
+
exports.Do = (0, exports.of)(_.emptyRecord);
|
|
4767
|
+
/**
|
|
4768
|
+
* @since 2.8.0
|
|
4769
|
+
*/
|
|
4770
|
+
exports.bindTo = (0, Functor.bindTo)(exports.Functor);
|
|
4771
|
+
/**
|
|
4772
|
+
* @since 2.8.0
|
|
4773
|
+
*/
|
|
4774
|
+
exports.bind = (0, Chain.bind)(exports.Chain);
|
|
4775
|
+
// -------------------------------------------------------------------------------------
|
|
4776
|
+
// pipeable sequence S
|
|
4777
|
+
// -------------------------------------------------------------------------------------
|
|
4778
|
+
/**
|
|
4779
|
+
* @since 2.8.0
|
|
4780
|
+
*/
|
|
4781
|
+
exports.apS = (0, Apply.apS)(exports.Apply);
|
|
4782
|
+
// -------------------------------------------------------------------------------------
|
|
4783
|
+
// deprecated
|
|
4784
|
+
// -------------------------------------------------------------------------------------
|
|
4785
|
+
/**
|
|
4786
|
+
* Use `NonEmptyArray` module instead.
|
|
4787
|
+
*
|
|
4788
|
+
* @category constructors
|
|
4789
|
+
* @since 2.0.0
|
|
4790
|
+
* @deprecated
|
|
4791
|
+
*/
|
|
4792
|
+
exports.range = NEA.range;
|
|
4793
|
+
/**
|
|
4794
|
+
* Use a new `[]` instead.
|
|
4795
|
+
*
|
|
4796
|
+
* @since 2.0.0
|
|
4797
|
+
* @deprecated
|
|
4798
|
+
*/
|
|
4799
|
+
exports.empty = [];
|
|
4800
|
+
/**
|
|
4801
|
+
* Use `prepend` instead.
|
|
4802
|
+
*
|
|
4803
|
+
* @category constructors
|
|
4804
|
+
* @since 2.0.0
|
|
4805
|
+
* @deprecated
|
|
4806
|
+
*/
|
|
4807
|
+
exports.cons = NEA.cons;
|
|
4808
|
+
/**
|
|
4809
|
+
* Use `append` instead.
|
|
4810
|
+
*
|
|
4811
|
+
* @category constructors
|
|
4812
|
+
* @since 2.0.0
|
|
4813
|
+
* @deprecated
|
|
4814
|
+
*/
|
|
4815
|
+
exports.snoc = NEA.snoc;
|
|
4816
|
+
/**
|
|
4817
|
+
* Use `prependAll` instead
|
|
4818
|
+
*
|
|
4819
|
+
* @category combinators
|
|
4820
|
+
* @since 2.9.0
|
|
4821
|
+
* @deprecated
|
|
4822
|
+
*/
|
|
4823
|
+
exports.prependToAll = exports.prependAll;
|
|
4824
|
+
/**
|
|
4825
|
+
* This instance is deprecated, use small, specific instances instead.
|
|
4826
|
+
* For example if a function needs a `Functor` instance, pass `A.Functor` instead of `A.array`
|
|
4827
|
+
* (where `A` is from `import A from 'fp-ts/Array'`)
|
|
4828
|
+
*
|
|
4829
|
+
* @category instances
|
|
4830
|
+
* @since 2.0.0
|
|
4831
|
+
* @deprecated
|
|
4832
|
+
*/
|
|
4833
|
+
exports.array = {
|
|
4834
|
+
URI: exports.URI,
|
|
4835
|
+
compact: exports.compact,
|
|
4836
|
+
separate: exports.separate,
|
|
4837
|
+
map: _map,
|
|
4838
|
+
ap: _ap,
|
|
4839
|
+
of: exports.of,
|
|
4840
|
+
chain: _chain,
|
|
4841
|
+
filter: _filter,
|
|
4842
|
+
filterMap: _filterMap,
|
|
4843
|
+
partition: _partition,
|
|
4844
|
+
partitionMap: _partitionMap,
|
|
4845
|
+
mapWithIndex: _mapWithIndex,
|
|
4846
|
+
partitionMapWithIndex: _partitionMapWithIndex,
|
|
4847
|
+
partitionWithIndex: _partitionWithIndex,
|
|
4848
|
+
filterMapWithIndex: _filterMapWithIndex,
|
|
4849
|
+
filterWithIndex: _filterWithIndex,
|
|
4850
|
+
alt: _alt,
|
|
4851
|
+
zero: exports.zero,
|
|
4852
|
+
unfold: exports.unfold,
|
|
4853
|
+
reduce: _reduce,
|
|
4854
|
+
foldMap: _foldMap,
|
|
4855
|
+
reduceRight: _reduceRight,
|
|
4856
|
+
traverse: _traverse,
|
|
4857
|
+
sequence: exports.sequence,
|
|
4858
|
+
reduceWithIndex: _reduceWithIndex,
|
|
4859
|
+
foldMapWithIndex: _foldMapWithIndex,
|
|
4860
|
+
reduceRightWithIndex: _reduceRightWithIndex,
|
|
4861
|
+
traverseWithIndex: _traverseWithIndex,
|
|
4862
|
+
extend: _extend,
|
|
4863
|
+
wither: _wither,
|
|
4864
|
+
wilt: _wilt
|
|
4865
|
+
};
|
|
4866
|
+
});
|
|
4867
|
+
|
|
4868
|
+
const _Array$1 = /*@__PURE__*/getDefaultExportFromCjs(_Array);
|
|
4869
|
+
|
|
4870
|
+
export { _Array as _, number as n };
|