"use strict"
var __createBinding =
  (this && this.__createBinding) ||
  (Object.create
    ? function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        Object.defineProperty(o, k2, {
          enumerable: true,
          get: function () {
            return m[k]
          }
        })
      }
    : function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        o[k2] = m[k]
      })
var __setModuleDefault =
  (this && this.__setModuleDefault) ||
  (Object.create
    ? function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v })
      }
    : function (o, v) {
        o["default"] = v
      })
var __importStar =
  (this && this.__importStar) ||
  function (mod) {
    if (mod && mod.__esModule) return mod
    var result = {}
    if (mod != null)
      for (var k in mod)
        if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
          __createBinding(result, mod, k)
    __setModuleDefault(result, mod)
    return result
  }
Object.defineProperty(exports, "__esModule", { value: true })
exports.replaceService_ =
  exports.replaceService =
  exports.replaceServiceM_ =
  exports.replaceServiceM =
  exports.provideService =
  exports.provideServiceM =
  exports.service =
  exports.accessService =
  exports.accessServiceM =
  exports.accessServices =
  exports.accessServicesT =
  exports.accessServicesTM =
  exports.accessServicesM =
    void 0
// tracing: off
/**
 * Copyright 2020 Michael Arnaldi and the Matechs Garage Contributors.
 */
const A = __importStar(require("../Collections/Immutable/Array"))
const R = __importStar(require("../Collections/Immutable/Dictionary"))
const Has_1 = require("../Has")
const X = __importStar(require("./core"))
/**
 * Access a record of services with the required Service Entries
 */
function accessServicesM(s) {
  return (f) => X.accessM((r) => f(R.map_(s, (v) => r[v.key])))
}
exports.accessServicesM = accessServicesM
const accessServicesTM =
  (...s) =>
  (f) =>
    X.accessM((r) => f(...A.map_(s, (v) => r[v.key])))
exports.accessServicesTM = accessServicesTM
function accessServicesT(...s) {
  return (f) => X.access((r) => f(...A.map_(s, (v) => r[v.key])))
}
exports.accessServicesT = accessServicesT
/**
 * Access a record of services with the required Service Entries
 */
function accessServices(s) {
  return (f) => X.access((r) => f(R.map_(s, (v) => r[v.key])))
}
exports.accessServices = accessServices
/**
 * Access a service with the required Service Entry
 */
function accessServiceM(s) {
  return (f) => X.accessM((r) => f(r[s.key]))
}
exports.accessServiceM = accessServiceM
/**
 * Access a service with the required Service Entry
 */
function accessService(s) {
  return (f) => accessServiceM(s)((a) => X.succeed(f(a)))
}
exports.accessService = accessService
/**
 * Access a service with the required Service Entry
 */
function service(s) {
  return accessServiceM(s)((a) => X.succeed(a))
}
exports.service = service
/**
 * Provides the service with the required Service Entry
 */
function provideServiceM(_) {
  return (f) => (ma) =>
    X.accessM((r) =>
      X.chain_(f, (t) => X.provideAll_(ma, (0, Has_1.mergeEnvironments)(_, r, t)))
    )
}
exports.provideServiceM = provideServiceM
/**
 * Provides the service with the required Service Entry
 */
function provideService(_) {
  return (f) => (ma) => provideServiceM(_)(X.succeed(f))(ma)
}
exports.provideService = provideService
/**
 * Replaces the service with the required Service Entry
 */
function replaceServiceM(_, f) {
  return (ma) => accessServiceM(_)((t) => provideServiceM(_)(f(t))(ma))
}
exports.replaceServiceM = replaceServiceM
/**
 * Replaces the service with the required Service Entry
 */
function replaceServiceM_(ma, _, f) {
  return accessServiceM(_)((t) => provideServiceM(_)(f(t))(ma))
}
exports.replaceServiceM_ = replaceServiceM_
/**
 * Replaces the service with the required Service Entry
 */
function replaceService(_, f) {
  return (ma) => accessServiceM(_)((t) => provideServiceM(_)(X.succeed(f(t)))(ma))
}
exports.replaceService = replaceService
/**
 * Replaces the service with the required Service Entry
 */
function replaceService_(ma, _, f) {
  return accessServiceM(_)((t) => provideServiceM(_)(X.succeed(f(t)))(ma))
}
exports.replaceService_ = replaceService_
//# sourceMappingURL=has.js.map
