Explorer

definy.apply-module-change

description
Apply one module change of definy_create_snapshot: delete the module, or change its descriptions (language by language), visibility and name
type
Fn(modules: List<@core.project-snapshot-module>, change: @definy.mcp-module-change) -> Union{#ok(List<@core.project-snapshot-module>), #error(String)}
expression
fn(modules$0, change$1) =>
  match @definy.snapshot-module-exists(modules: $0, name: $1.module) {
    false =>
      #error(@std.string-join(items: ["Module ", $1.module, " was not found"], separator: "")),
    true =>
      match $1.delete {
        true =>
          #ok(@core.list-fold(
            T: @core.project-snapshot-module,
            A: List<@core.project-snapshot-module>,
            reducer: fn(acc$2, item$3) =>
              match @core.equal(left: $3.name, right: $1.module) {
                true =>
                  $2,
                false =>
                  @core.list-append(list: $2, item: $3)
              },
            init: [],
            xs: $0
          )),
        false =>
          let name$4 = match $1.rename {
              #some(text$5) =>
                $5,
              #none(_) =>
                $1.module
            };
          match @core.and(
              left: @core.not(value: @core.equal(left: $4, right: $1.module)),
              right: @definy.snapshot-module-exists(modules: $0, name: $4)
            ) {
            true =>
              #error(@std.string-join(items: ["Module ", $4, " already exists"], separator: "")),
            false =>
              #ok(@core.list-map(
                T: @core.project-snapshot-module,
                U: @core.project-snapshot-module,
                f: fn(item$6) =>
                  match @core.equal(left: $6.name, right: $1.module) {
                    true =>
                      {
                        name: $4,
                        description: @definy.localized-texts-update(texts: $6.description, english: $1.description, others: $1.descriptions),
                        visibility: match $1.visibility {
                          #some(visibility$8) =>
                            $8,
                          #none(_) =>
                            $6.visibility
                        },
                        parts: $6.parts
                      },
                    false =>
                      $6
                  },
                xs: $0
              ))
          }
      }
  }
visibility
public
definy.apply-module-change (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: KvIOA1fbyfrnAIdp8LsUrOAmLcrrZ2ZJx_cZzUGQy0k
content hash: 9iBU-RfJsSxVLUqfaR09faxP3FzNPwweS2mhztb1Bqo