[openstack-dev] [Heat] Conditionals, was: New function: first_nonnull

Clint Byrum clint at fewbar.com
Tue Nov 11 18:12:33 UTC 2014


Excerpts from Alexis Lee's message of 2014-11-10 09:34:13 -0800:
> Zane Bitter said on Fri, Nov 07, 2014 at 12:35:09AM +0100:
> > Crazy thought: why not just implement conditionals? We had a
> > proto-spec for them started at one point...
> 
> I didn't know that was on the table :)
> 
> How about we support YAQL expressions? https://github.com/ativelkov/yaql
> Plus some HOFs (higher-order functions) like cond, map, filter, foldleft
> etc?
> 
> Here's first_nonnull:
> 
>   config:
>     Fn::Select
>       - 0
>       filter:
>         - yaql: "$.0 != null"
>         - <item1>
>         - <itemN>
> 
> Making the 'yaql' function eponymous means we can easily plug other
> expression languages in later if we choose.
> 

Cool. I think this aligns nicely with my suggestion at the summit that
we also allow writing functions in javascript. This would allow people
to write their own first_nonnull/coalesce until we have a chance to add
it:

  config:
    embed:
      lang: javascript
      args: - item1
            - item2
      code: |
        for (arg in args) {
          if (arg !== null) {
            return arg
          }
        }
        return null;

I'd really love to have this functionality but I doubt I'll have time to
spec and land it. Does anybody else think this functionality would be a
good way to allow template authors flexibility that they desire?



More information about the OpenStack-dev mailing list