Skip to content

Conversation

@johnhammerlund
Copy link
Contributor

ExpressionArgumentBuilder currently only supports the basic buildBlock(...) method, but not loop expressions or conditional expressions. There are cases where these can simplify logic, reduce constants, etc. For example, a SymbolLayer may have a large matrix of icons:

let iconImageExp = Exp(.match) {
    "make"
    
    "ford"
    Exp(.match) {
        "color"
        
        "red"
        "red-ford-icon"

        "green"
        "green-ford-icon"
    }

    "chevy"
    Exp(.match) { ... }
}

We could instead leverage Swift a bit more:

let iconImageExp = Exp(.match) {
    "make"
    for make in CarMake.allCases {
        make.featureValue
        Exp(.match) {
            "color"
            for color in CarColor.allCases {
                color.featureValue
                make.iconID(color: color)
            }
        }
    }
}

The second example is not currently possible. This PR adds support for loops/arrays as well as conditionals. Some feature examples have been updated to leverage this, but happy to revert that if desired.

Pull request checklist:

  • Describe the changes in this PR, especially public API changes.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality. Put tests in correct Test Plan (Unit, Integration, All)
    • If tests were not written, please explain why.
  • Add documentation comments for any added or updated public APIs.
  • Add any new public, top-level symbols to the DocC custom catatlog (Sources/MapboxMaps/Documentation.docc/API Catalogs)
  • Add a changelog entry to to bottom of the relevant section (typically the ## main heading near the top).
  • Update the guides (internal access only), README.md, and DEVELOPING.md if their contents are impacted by these changes.
  • If this PR is a v10.[version] release branch fix / enhancement, merge it to main first and then port to v10.[version] release branch.

PRs must be submitted under the terms of our Contributor License Agreement CLA.

@johnhammerlund johnhammerlund requested a review from a team as a code owner August 7, 2025 16:00
@johnhammerlund johnhammerlund requested a review from OdNairy August 7, 2025 16:00
@CLAassistant
Copy link

CLAassistant commented Aug 7, 2025

CLA assistant check
All committers have signed the CLA.

@OdNairy
Copy link
Contributor

OdNairy commented Aug 8, 2025

Looks great! Thank you, @johnhammerlund
I will get back to the PR next week, review and merge it 👍

P.S. (just for me) The internal ticket for this request was MAPSIOS-413

@OdNairy
Copy link
Contributor

OdNairy commented Aug 8, 2025

Also congrats on your first PR 🎉

@johnhammerlund
Copy link
Contributor Author

Hello @OdNairy , any updates on this? Thanks!

@OdNairy OdNairy changed the base branch from main to expand-expression-dsl September 19, 2025 12:03
@OdNairy OdNairy merged commit 92f6d5b into mapbox:expand-expression-dsl Sep 19, 2025
1 check passed
@OdNairy
Copy link
Contributor

OdNairy commented Sep 19, 2025

Hey @johnhammerlund
Sorry for a delay. I've merged your PR to the different base branch so I could process it appropriately internally

mapbox-github-ci-writer-public-1 bot pushed a commit that referenced this pull request Sep 24, 2025
Original PR:
- #2355

Resolves MAPSIOS-413

`ExpressionArgumentBuilder` currently only supports the basic
`buildBlock(...)` method, but not loop expressions or conditional
expressions. There are cases where these can simplify logic, reduce
constants, etc. For example, a `SymbolLayer` may have a large matrix of
icons:

```swift
let iconImageExp = Exp(.match) {
    "make"

    "ford"
    Exp(.match) {
        "color"

        "red"
        "red-ford-icon"

        "green"
        "green-ford-icon"
    }

    "chevy"
    Exp(.match) { ... }
}
```

We could instead leverage Swift a bit more:

```swift
let iconImageExp = Exp(.match) {
    "make"
    for make in CarMake.allCases {
        make.featureValue
        Exp(.match) {
            "color"
            for color in CarColor.allCases {
                color.featureValue
                make.iconID(color: color)
            }
        }
    }
}
```

The second example is not currently possible. This PR adds support for
loops/arrays as well as conditionals. Some feature examples have been
updated to leverage this, but happy to revert that if desired.

## Pull request checklist:
 - [x] Describe the changes in this PR, especially public API changes.
- [ ] Include before/after visuals or gifs if this PR includes visual
changes.
    <!--
        | Before | After |
        | ----- | ----- |
        | <img src="" width = 250/> | <img src="" width = 250/> |
        or
        | <video src="" width = 250/> | <video src="" width = 250/> |
    -->
- [x] Write tests for all new functionality. Put tests in correct [Test
Plan](https://github.com/mapbox/mapbox-maps-ios/tree/main/Tests/TestPlans)
(Unit, Integration, All)
   - [ ] If tests were not written, please explain why.
 - [ ] Add documentation comments for any added or updated public APIs.
- [ ] Add any new public, top-level symbols to the DocC custom catatlog
(Sources/MapboxMaps/Documentation.docc/API Catalogs)
- [ ] Add a changelog entry to to bottom of the relevant section
(typically the `## main` heading near the top).
- [ ] Update the guides (internal access only), README.md, and
DEVELOPING.md if their contents are impacted by these changes.
- [ ] If this PR is a `v10.[version]` release branch fix / enhancement,
merge it to `main` first and then port to `v10.[version]` release
branch.

PRs must be submitted under the terms of our Contributor License
Agreement
[CLA](https://github.com/mapbox/mapbox-maps-ios/blob/main/CONTRIBUTING.md#contributor-license-agreement).

cc @mapbox/maps-ios

cc @mapbox/sdk-ci

---------

Co-authored-by: John Hammerlund <[email protected]>
GitOrigin-RevId: 1a2bb8e04b44dadf8e1bd901b8b9e6429865daad
@OdNairy
Copy link
Contributor

OdNairy commented Sep 24, 2025

@johnhammerlund Heads up that PR was merged and available in the main branch:

Thank you very much for such a nice addition!

@johnhammerlund
Copy link
Contributor Author

Excellent, appreciate it! Thanks @OdNairy 👍

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.

3 participants