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

Nested params and json/yaml files #50

Merged
merged 10 commits into from
Nov 7, 2022
Merged

Nested params and json/yaml files #50

merged 10 commits into from
Nov 7, 2022

Conversation

lukfor
Copy link
Collaborator

@lukfor lukfor commented Nov 3, 2022

Fixes #15

Copy link
Contributor

@aaron-fishman-achillestx aaron-fishman-achillestx left a comment

Choose a reason for hiding this comment

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

This feature is very cool! Particularly how you can mix/match loading of json and defining locally.

My main comment is a suggestion to use an iterative rather than recursive schemes (I was always taught to use iterative over the latter when possible!).

src/main/java/com/askimed/nf/test/lang/ParamsMap.java Outdated Show resolved Hide resolved
src/main/java/com/askimed/nf/test/lang/ParamsMap.java Outdated Show resolved Hide resolved

}

protected void evaluateNestedClosures(Map<String, Object> map) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could also be written iteratively:

	protected void evaluateNestedClosures(Map<String, Object> map) {

        Queue< Map<String, Object> > queue = new LinkedList< Map<String, Object> >();
        queue.add(map);

        while (queue.size() > 0) {
            Map<String, Object> item = queue.remove();

            for (String key : item.keySet()) {
                Object value = item.get(key);

                if (!(value instanceof Closure)) continue; 

                Map<String, Object> nestedMap = createNestedMap();
                Closure closure = (Closure) value;
                closure.setDelegate(nestedMap);
                closure.setResolveStrategy(Closure.DELEGATE_FIRST);
                closure.call();
                item.put(key, nestedMap);
                
                queue.add(nestedMap); // Instead of recursion
    
            }

        }
	}

test-data/pipeline/dsl1/test1.nf.test Show resolved Hide resolved
@lukfor
Copy link
Collaborator Author

lukfor commented Nov 4, 2022

Great idea, thanks Aaron! 👍

@lukfor lukfor merged commit 85258f8 into main Nov 7, 2022
@lukfor lukfor deleted the features/load-params branch November 7, 2022 09: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.

Nested params
2 participants