forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filterA to Prelude (digital-asset#5809)
* CHANGELOG_BEGIN Added filterA to Prelude. * Update compiler/damlc/daml-stdlib-src/DA/Internal/Prelude.daml Co-authored-by: Shayne Fletcher <shayne@shaynefletcher.org> * Removed not so useful comment. * Moved filterA from Prelude to Action. * filterA is a one-liner now. * Provided more meaningful example to filterA. * Added test for filterA. * Removed failing doctest. CHANGELOG_END Co-authored-by: Shayne Fletcher <shayne@shaynefletcher.org>
- Loading branch information
1 parent
572b21e
commit 6f1d221
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates. | ||
-- All rights reserved. | ||
|
||
module ActionTest where | ||
|
||
import DA.Assert | ||
import DA.Action | ||
|
||
import Iou12 | ||
|
||
testFilterA: Scenario () | ||
testFilterA = scenario do | ||
bank <- getParty "Acme Bank" | ||
alice <- getParty "Alice" | ||
bob <- getParty "Bob" | ||
charlie <- getParty "Charlie" | ||
let | ||
aliceIou = Iou bank alice "USD" 1.23 [] | ||
bobIou = Iou bank bob "GBP" 2.34 [] | ||
charlieIou = Iou bank charlie "EUR" 3.45 [] | ||
ious = [aliceIou, bobIou, charlieIou] | ||
|
||
iouIds <- bank `submit` forA ious create | ||
|
||
aliceIouIds <- bank `submit` filterA (fmap (\iou -> iou.owner == alice) . fetch) iouIds | ||
aliceIous <- bank `submit` forA aliceIouIds fetch | ||
[aliceIou] === aliceIous | ||
|
||
largeIouIds <- bank `submit` filterA (fmap (\iou -> iou.amount > (2.0 : Decimal)) . fetch) iouIds | ||
largeIous <- bank `submit` forA largeIouIds fetch | ||
[bobIou, charlieIou] === largeIous |