将不同模式与联合值关联起来的 dhall 惯用方法是什么?

2024-02-21

我试图使用 Dhall 类型来表示 Zuul-CI 项目的管道系统: 管道可以使用具有不同触发事件的不同连接。

我想提供一个默认管道,为每种类型的连接设置正确的触发事件,方式如下:

  ⊢ RenderPipeline CheckPipeline::{ connections = [ ConnectionTypes.GitHub ] }

  - pipeline:
    name: check
    trigger:
      github:
        action: open
        event: pull-request

  ⊢ RenderPipeline CheckPipeline::{ connections = [ ConnectionTypes.Gerrit ] }

  - pipeline:
    name: check
    trigger:
      gerrit:
        event: patchset-created

  ⊢ RenderPipeline CheckPipeline::{ connections = [ ConnectionTypes.Gerrit, ConnectionTypes.GitHub ] }

  - pipeline:
      name: check
      trigger:
        gerrit:
          event: patchset-created
        github:
          action: open
          event: pull-request

我必须对 ConnectionTrigger 使用 Union,因为合并函数期望该值是单一类型。

有没有办法以某种方式将 GerritTrigger 与 ConnectionTypes.Gerrit 关联起来,并避免在 CheckPipeline 定义中键入事件类型(例如删除 ConnectionTrigger.Gerrit 注释)?

let Prelude =
      https://raw.githubusercontent.com/dhall-lang/dhall-lang/v11.1.0/Prelude/package.dhall sha256:99462c205117931c0919f155a6046aec140c70fb8876d208c7c77027ab19c2fa

let ConnectionTypes
    : Type
    = < Gerrit | GitHub >

let GerritTrigger
    : Type
    = { event : Text }

let GitHubTrigger
    : Type
    = { event : Text, action : Text }

let ConnectionTrigger
    : Type
    = < Gerrit : GerritTrigger | GitHub : GitHubTrigger >

let Pipeline
    : Type
    = { name : Text
      , trigger : { Gerrit : ConnectionTrigger, GitHub : ConnectionTrigger }
      , connections : List ConnectionTypes
      }

let CheckPipeline =
      { Type = Pipeline
      , default =
          { name = "check"
          , trigger =
              -- "Here, can this be improved so that Gerrit is not mentioned twice?"
              { Gerrit = ConnectionTrigger.Gerrit { event = "patchset-created" }
              , GitHub =
                  ConnectionTrigger.GitHub
                    { event = "pull-request", action = "open" }
              }
          }
      }

let PipelineRenderTrigger
    : Type
    = { mapKey : Text, mapValue : ConnectionTrigger }

let RenderPipeline =
        λ(pipeline : Pipeline)
      → [ { pipeline =
              { name = pipeline.name
              , trigger =
                  Prelude.List.map
                    ConnectionTypes
                    PipelineRenderTrigger
                    (   λ(connection : ConnectionTypes)
                      → { mapKey =
                            merge
                              { Gerrit = "gerrit", GitHub = "github" }
                              connection
                        , mapValue = merge pipeline.trigger connection
                        }
                    )
                    pipeline.connections
              }
          }
        ]

in  RenderPipeline CheckPipeline::{ connections = [ ConnectionTypes.GitHub ] }

提前致谢 :)


是的,您可以通过转换来做到这一点triggers字段,然后将其作为处理程序的记录传递给merge。这样用户就不必自己包装触发器;这RenderPipeline函数为他们做这件事:

let Prelude =
      https://raw.githubusercontent.com/dhall-lang/dhall-lang/v11.1.0/Prelude/package.dhall sha256:99462c205117931c0919f155a6046aec140c70fb8876d208c7c77027ab19c2fa

let ConnectionTypes
    : Type
    = < Gerrit | GitHub >

let GerritTrigger
    : Type
    = { event : Text }

let GitHubTrigger
    : Type
    = { event : Text, action : Text }

let ConnectionTrigger
    : Type
    = < Gerrit : GerritTrigger | GitHub : GitHubTrigger >

let Pipeline
    : Type
    = { name : Text
      , trigger : { Gerrit : GerritTrigger, GitHub : GitHubTrigger }
      , connections : List ConnectionTypes
      }

let CheckPipeline =
      { Type = Pipeline
      , default =
          { name = "check"
          , trigger =
              { Gerrit = { event = "patchset-created" }
              , GitHub = { event = "pull-request", action = "open" }
              }
          }
      }

let PipelineRenderTrigger
    : Type
    = { mapKey : Text, mapValue : ConnectionTrigger }

let RenderPipeline =
        λ ( pipeline
          : Pipeline
          )
      → [ { pipeline =
              { name =
                  pipeline.name
              , trigger =
                  Prelude.List.map
                    ConnectionTypes
                    PipelineRenderTrigger
                    (   λ ( connection
                          : ConnectionTypes
                          )
                      → { mapKey =
                            merge
                              { Gerrit = "gerrit", GitHub = "github" }
                              connection
                        , mapValue =
                            let {- This is the key bit!

                                   We modify the handlers before passing them to
                                   `merge` so that the user does not have to
                                -}
                                trigger =
                                  { Gerrit =
                                      ConnectionTrigger.Gerrit
                                        pipeline.trigger.Gerrit
                                  , GitHub =
                                      ConnectionTrigger.GitHub
                                        pipeline.trigger.GitHub
                                  }

                            in  merge trigger connection
                        }
                    )
                    pipeline.connections
              }
          }
        ]

in  RenderPipeline CheckPipeline::{ connections = [ ConnectionTypes.GitHub ] }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将不同模式与联合值关联起来的 dhall 惯用方法是什么? 的相关文章

  • Ellipsize 属性在 Android 4.0 上不起作用

    我目前正在 Android 4 0 Ice Cream Sandwich 上测试一个应用程序 然后再向市场发布更新 在测试过程中 我意识到椭圆形属性停止工作 我在列表视图上使用它来截断太长的项目标题 在 Android 2 3 7 上 一切
  • oracle中的子选择

    我正在尝试从子选择中的另一个表中选择最新价格 但我不知道如何让它发挥作用 这是我尝试过的 select something somthingelse select from select QUOTE PRICE as old price f
  • Android Firebase:无法解析

    我尝试将 Firebase 与我的应用程序连接 但出现了此错误 这是我的 build gradle 项目 Top level build file where you can add configuration options common
  • createReadStream() 抛出 RangeError:上传文件时超出最大调用堆栈大小

    我正在尝试使用 Apollo 服务器Upload直接将文件发送到 S3 的标量 我的架构 const gql require apollo server express module exports gql extend type Muta
  • Python:使用“copyreg”为已有减速器的类型定义减速器

    请记住 我正在使用 Python 3 工作 因此解决方案需要在 Python 3 中工作 我想使用copyreg教 Python 如何 pickle 函数的模块 当我尝试这样做时 Pickler对象仍然会尝试使用 pickle 函数save
  • NSURLSessionConfiguration 和 NSURLRequest 具有相同的属性吗?

    我在官方文档中看到 NSURLSessionConfiguration 和 NSURLRequest 共享一些相同或相似的属性 比如NSURLRequestCachePolicy networkServiceType timeOurInte
  • 在具有属性的两个表单之间传递数据[重复]

    这个问题在这里已经有答案了 我正在 C 中的 2 个窗口窗体之间传递数据 Form1 是主窗体 其文本框将接收从 form2 textbox 传递给它的文本并将其显示在其文本框 form1 textbox 中 首先 form1 打开 带有一
  • React 测试库 - 在 fireEvent 之后使用“await wait()”

    我正在尝试使用测试库在 fireEvent click 之后检查 DOM 元素 我知道我需要在 fireEvent 之后等待 但不确定为什么简单地使用 wait 不起作用 下面是以两种方式编写的相同测试 第一个失败 第二个通过 我不明白为什
  • .htaccess 将index.php重定向到/

    我想隐藏index php页面并只显示域 htaccess 可以吗 RewriteRule index php L R 301 NC 还尝试过 RewriteEngine On RewriteBase RewriteCond THE REQ
  • 导航抽屉未正确显示

    我正在开发新闻应用程序 并且已经实现了导航抽屉 使用以下link https guides codepath com android fragment navigation drawer但是当我运行代码应用程序时显示空白色 屏幕 在我的 M
  • 附加选项以选择菜单?

    使用 Javascript 如何将选项附加到 HTML 选择菜单 例如
  • 使用任务时如何使用上一个任务的结果继续另一个函数?

    我有 WCF 连接器 它应该为我获取一些少量的数据 通常需要 20 秒才能获取每个项目的数据 这很好 我想使用任务为我获取数据 然后添加具有此任务值的 WinForm 控件 我已经创建了包含这些数据的对象列表 使用第一个任务作为更新列表的任
  • 如何在graphviz中强制Y坐标

    有没有办法在 graphviz 中使用 dot force y 位置 以像素或英寸为单位 The rank same不适合我的情况 The pos x y with Kfdp可能是一种方法 但我想让 GraphViz 确定 X位置 Than
  • 用于过滤项目集合的设计模式?

    想象一下典型的应用程序类型 其中您有一个具有不同属性的项目列表 例如 包含 100 个项目的树视图 每个项目都有一个name a rating a 全球最热门商品排名等等 之间可能也存在多对多的关系items and 项目目录 或之间ite
  • 简单的 Node/Express 应用程序,函数式编程方式(如何处理 JavaScript 中的副作用?)

    有很多关于 JavaScript 函数式编程理论的好文章 有些甚至包含显示命令式 面向对象编程和声明式 函数式编程之间差异的代码示例 但我没有发现任何一个可以通过简单的 JavaScript 代码示例来展示如何处理 Web 应用程序中的副作
  • c中的嵌套结构

    我必须构建一个嵌套结构来存储有关某人的一些基本信息 姓名 年龄 地址 因此 我创建了一个名为 info 的结构 并为了保存地址 我在 info 内创建了另一个名为 address 的嵌套结构 但每当我提示使用 for 循环存储值时 我都会收
  • 升级依赖项后无法解析 ActivityTestRule。无法导入 ActivityTestRule

    我已经编写了工作正常的仪器测试 但现在在将依赖项升级到之后出现错误无法解决 ActivityTestRule 错误 androidTestImplementation com android support test runner 1 0

随机推荐