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

Additional Operations #1

Open
chongkong opened this issue Jul 25, 2016 · 1 comment
Open

Additional Operations #1

chongkong opened this issue Jul 25, 2016 · 1 comment

Comments

@chongkong
Copy link
Owner

chongkong commented Jul 25, 2016

Currently supported operations are

  1. String interpolation
  2. Scope injection using <
  3. String filtering using |
  4. Fallback from undefined using ??

Although combinations of above operations can structure many of the configuration, there is some limitations to achieve everything. This issue is a small proposal for future improvements of operations

List Operation

Merging two lists

{
  "plus": "{{ first + second }}",
  "colons": "{{ first::second }}",
  "array_unpack": ["*{{ first }}", "*{{ second }}" ]
}

Mapping injection with list of scope (really required?)

{
  "scopes": [
    { "name": "foo" },
    { "name": "bar" },
    { "name": "cor" },
    { "name": "giz" }
  ]
}

{
  "greeting": "hello, {{ name }}",
  "greetings": "{{ greeting << scopes }}",
  "greetings2": [
    "{% for scope in scopes %}",
    "{{ greeting < scope }}",
    "{% end for %}"
  ]
}

Unique filter

{
   "duplicated": [1, 1, 2, 3, 3, 3],
   "unqiue" : "{{ duplicated | unique }}"
}

Dictionary

Merging two dictionary (really required?)

{
  "plus": "{{ first + second }}",
  "unpack": [
    "**{{ this_is_weird }}",
    "**{{ looks_like_an_array }}"
  ]
}

Integer Operation

Simple integer operation

{
   "one": 1,
   "two": "{{ one + 1 }}",
   "three": "{{ one * 3 }}",
   "four": "{{ two * two }}",
   "five": "{{ 10 / two }}"
}
@chongkong
Copy link
Owner Author

chongkong commented Jul 25, 2016

I think adding +, -, *, / operators and defining operation priority seems the clearest.

But I also want some kind of list-comprehension-like syntax, like

[
  "{% for scope in scopes %}",
  "{{ greeting < scope }}",
  "{% end for %}"
]

or

{
  "for_comprehension": "{{ foo.bar for foo in foos }}",
  "map": "{{ foos map bar }}",
  "dot_operator": "{{ foos.bar }}",
  "dot_operator_with_other": [
    "{{ foos .+ 1 }}",
    "{{ foos .?? fallback }}",
    "{{ foos .< scopes }}"
  ]
}

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

No branches or pull requests

1 participant