First Meeting Condition

Last updated on
20 November 2022

Returns first value in array meeting condition.

first_meeting_condition is a generalization of core's null_coalesce process plugin that uses a condition instead of is_null(). It can create this "empty_coalesce" feature request, for example.

Available configuration keys:

  • condition: The condition plugin to evaluate. Can be either:
    1. The id of the condition. This is possible if the condition does not require any configuration, such as the 'empty' condition.
    2. An array with a 'plugin' key that is the id of the condition. Any additional properties will be used as configuration when creating an instance of the condition.
  • default_value: (optional) The value to return if no values in the source meet the condition. This must be a string literal, not a source or destination property.

Please note that when using 'first_meeting_condition', it makes no sense to configure the 'source' directly on the condition.

Examples

1. Re-create core null_coalesce

process:
  some_not_null_value:
    plugin: first_meeting_condition
    condition: not:is_null
    source:
      - something
      - something_else
      - whatever
    default_value: 'If all else fails'

2. Make an "empty coalesce" plugin

Sometimes "is_null" is too high a bar. Maybe we don't want empty strings or false either.

process:
  some_not_empty_value:
    plugin: first_meeting_condition
    condition: not:empty
    source:
      - something
      - something_else
      - whatever
    default_value: 'If all else fails'

Help improve this page

Page status: No known problems

You can: