@Nullable
    public static FlatMapOperation from(ChainVariable outVar, PsiExpression arg, boolean supportUnknownSources) {
      FunctionHelper fn = FunctionHelper.create(arg, 1);
      if(fn == null) return null;
      String varName = fn.tryLightTransform();
      if(varName == null) return null;
      PsiExpression body = PsiUtil.skipParenthesizedExprDown(fn.getExpression());
      PsiExpression condition = null;
      boolean inverted = false;
      if(body instanceof PsiConditionalExpression ternary) {
        condition = ternary.getCondition();
        PsiExpression thenExpression = PsiUtil.skipParenthesizedExprDown(ternary.getThenExpression());
        PsiExpression elseExpression = PsiUtil.skipParenthesizedExprDown(ternary.getElseExpression());
        if(StreamApiUtil.isNullOrEmptyStream(thenExpression)) {
          body = elseExpression;
          inverted = true;
        }
        else if(StreamApiUtil.isNullOrEmptyStream(elseExpression)) {
          body = thenExpression;
        }
        else return null;
      }
      if(!(body instanceof PsiMethodCallExpression terminalCall)) return null;
      List<StreamToLoopInspection.OperationRecord> records =
        StreamToLoopInspection.extractOperations(outVar, terminalCall, supportUnknownSources);
      if(records == null || StreamToLoopInspection.getTerminal(records) != null) return null;
      return new FlatMapOperation(varName, fn, records, condition, inverted);
    }
@Nullable
    public static FlatMapOperation from(ChainVariable outVar, PsiExpression arg, boolean supportUnknownSources)