-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reflow/syntax: implement full comprehension support (cross products, …
…filters) Summary: This change adds full comprehension support into Reflow. Before this change, Reflow supported only a limited form of comprehensions: mapping over a single list or map. This change introduces support for cross products and predicates, which can be combined arbitrarily. Each comprehension takes a number of clauses, each of which is either an "enumeration" or a "filter". Enumerations are the familiar pat <- e1 form, while filters are of the form if e1 The list of clauses are separated by commas. After this change, all of the following work: val TestCompr = { l := [1,2,3,4,5,6,7,8,9] x2 := [x*2 | x <- l] test.All([x*2 == y | (x, y) <- zip(l, x2)]) } val TestCompr2 = { strings := make("$/strings") x := ["a", "b", "c"] y := [1, 2] xy := [x + strings.FromInt(y) | x <- x, y <- y] test.All([x == y | (x, y) <- zip(xy, ["a1", "a2", "b1", "b2", "c1", "c2"])]) } val TestCompr3 = { xs := [1,2,3,4] xy := [x*y | x <- xs, if x%2 == 0, y <- xs] expect := [2, 4, 6, 8, 4, 8, 12, 16] test.All([x == y | (x, y) <- zip(xy, expect)]) } val TestCompr4 = { xss := [["a", "b", "c"], ["e"], ["f", "g", "h"]] xy := [x | xs <- xss, x <- xs, if x != "a"] expect := ["b", "c", "e", "f", "g", "h"] test.All([x == y | (x, y) <- zip(xy, expect)]) } Full comprehensions can replace a lot of other ad-hoc functionality. For example, flatten(x) can be expressed as [x | xxs <- xs, x <- xs]. There is other existing Reflow code which could benefit from filtering (e.g., filter a directory of files). Reviewers: pgopal, escott Reviewed By: pgopal Subscribers: sbagaria, escott Differential Revision: https://phabricator.grailbio.com/D8862 fbshipit-source-id: 091a8a9
- Loading branch information
Showing
12 changed files
with
3,409 additions
and
983 deletions.
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
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
Oops, something went wrong.