Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filterA to Prelude #5809

Merged
merged 8 commits into from
May 4, 2020

Conversation

tamaskalcza-da-zz
Copy link
Contributor

@tamaskalcza-da-zz tamaskalcza-da-zz commented Apr 30, 2020

Pull Request Checklist

  • Read and understand the contribution guidelines
  • Include appropriate tests
  • Set a descriptive title and thorough description
  • Add a reference to the issue this PR will solve, if appropriate
  • Include changelog additions in one or more commit message bodies between the CHANGELOG_BEGIN and CHANGELOG_END tags
  • Normal production system change, include purpose of change in description

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

filterA

Implemented a filterA function using the approach borrowed from mapA in the standard library (and the filterM in Haskell).

Given the "classic" Iou example if one has a collection of ContractId Ious and is interested in only the "large ones" he could use this new filter like this:

filter_ious: Scenario ()
filter_ious = scenario do
  issuer <- getParty "John Doe"

  let
    usd = Iou issuer issuer "USD" 1.23 []
    gbp = Iou issuer issuer "GBP" 2.34 []
    eur = Iou issuer issuer "EUR" 3.45 []
    ious = [usd, gbp, eur]

    largeIou iouId = do
      iou <- fetch iouId
      pure $ iou.amount > (2.0 : Decimal)

  iouIds <- issuer `submit` forA ious create

  largeIds <- issuer `submit` filterA largeIou iouIds

  largeIous <- issuer `submit` forA largeIds fetch
  [gbp, eur] === largeIous

Added filterA to Prelude.
Copy link
Contributor

@shayne-fletcher shayne-fletcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition! Couple of suggestions inline.

compiler/damlc/daml-stdlib-src/DA/Internal/Prelude.daml Outdated Show resolved Hide resolved
compiler/damlc/daml-stdlib-src/DA/Internal/Prelude.daml Outdated Show resolved Hide resolved
compiler/damlc/daml-stdlib-src/DA/Internal/Prelude.daml Outdated Show resolved Hide resolved
compiler/damlc/daml-stdlib-src/DA/Internal/Prelude.daml Outdated Show resolved Hide resolved
@tamaskalcza-da-zz tamaskalcza-da-zz marked this pull request as ready for review May 1, 2020 01:03
Copy link
Contributor

@shayne-fletcher shayne-fletcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to see a test added for this but given the apparent absence of tests for the other DA.Action functions, I think this could be done in a follow up PR.

@shayne-fletcher
Copy link
Contributor

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@cocreature
Copy link
Contributor

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@cocreature
Copy link
Contributor

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@cocreature cocreature merged commit 6f1d221 into digital-asset:master May 4, 2020
@tamaskalcza-da-zz tamaskalcza-da-zz deleted the add-filterA branch May 27, 2020 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants