<commit_before>{lib}:

rec {
  inherit (builtins) listToAttrs attrNames getAttr hasAttr;
  inherit (lib) filter elem;

  filterDerivations = services:
    listToAttrs (map (serviceName:
      let
        service = getAttr serviceName services;
      in
      { name = serviceName;
        value = listToAttrs(map (propertyName:
	          { name = propertyName; value = getAttr propertyName service; }
		  ) (filter (propertyName: propertyName != "pkg" && propertyName != "dependsOn") (attrNames service)))
		;
      }
    ) (attrNames services))
  ;
  
  createCartesianProduct = {services, infrastructure}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value = map (targetName: targetName) (attrNames infrastructure);
      }
    ) (attrNames services))
  ;
  
  mapAttrOnList = {distribution, services, infrastructure, serviceProperty, targetPropertyList}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value = 
          let
            servicePropertyValue = getAttr serviceProperty (getAttr serviceName services);
	    targets = getAttr serviceName distribution;
          in
          filter (targetName: 
            let
	      target = getAttr targetName infrastructure;
	      targetPropertyListValue = getAttr targetPropertyList target;
	    in
	      elem servicePropertyValue targetPropertyListValue
          ) targets;
      }
    ) (attrNames distribution))
  ;
  
  mapListOnAttr = {distribution, services, infrastructure, servicePropertyList, targetProperty}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value = 
	  let
	    targets = getAttr serviceName distribution;
	    service = getAttr serviceName services;
	    servicePropertyListValue = getAttr servicePropertyList service;
	  in
	  filter (targetName:
	    let
	      target = getAttr targetName infrastructure;
	      targetPropertyValue = getAttr targetProperty target;
	    in
	      elem targetPropertyValue servicePropertyListValue
	  ) targets;
      }
    ) (attrNames distribution))
  ;
  
  mapAttrOnAttr = {distribution, services, infrastructure, serviceProperty, targetProperty}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value =
	  let
	    servicePropertyValue = getAttr serviceProperty (getAttr serviceName services);
	    targets = getAttr serviceName distribution;
	  in
	  filter (targetName:
	    let
	      targetPropertyValue = getAttr targetProperty (getAttr targetName infrastructure);
	    in
	    servicePropertyValue == targetPropertyValue
	  ) targets;
      }
    ) (attrNames distribution))
  ;
  
  mapStatefulToPrevious = {services, distribution, previousDistribution}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value =
          let
            service = getAttr serviceName services;
	    targets = getAttr serviceName distribution;
	    previousTargets = if hasAttr serviceName previousDistribution then getAttr serviceName previousDistribution
	                      else targets;
          in
          if service ? stateful && service.stateful then
	    filter (targetName: elem targetName previousTargets) targets
	  else targets;
      }
    ) (attrNames distribution))
  ;
}<commit_msg>Deal with previousDistribution == null<commit_after>{lib}:

rec {
  inherit (builtins) listToAttrs attrNames getAttr hasAttr;
  inherit (lib) filter elem;

  filterDerivations = services:
    listToAttrs (map (serviceName:
      let
        service = getAttr serviceName services;
      in
      { name = serviceName;
        value = listToAttrs(map (propertyName:
	          { name = propertyName; value = getAttr propertyName service; }
		  ) (filter (propertyName: propertyName != "pkg" && propertyName != "dependsOn") (attrNames service)))
		;
      }
    ) (attrNames services))
  ;
  
  createCartesianProduct = {services, infrastructure}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value = map (targetName: targetName) (attrNames infrastructure);
      }
    ) (attrNames services))
  ;
  
  mapAttrOnList = {distribution, services, infrastructure, serviceProperty, targetPropertyList}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value = 
          let
            servicePropertyValue = getAttr serviceProperty (getAttr serviceName services);
	    targets = getAttr serviceName distribution;
          in
          filter (targetName: 
            let
	      target = getAttr targetName infrastructure;
	      targetPropertyListValue = getAttr targetPropertyList target;
	    in
	      elem servicePropertyValue targetPropertyListValue
          ) targets;
      }
    ) (attrNames distribution))
  ;
  
  mapListOnAttr = {distribution, services, infrastructure, servicePropertyList, targetProperty}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value = 
	  let
	    targets = getAttr serviceName distribution;
	    service = getAttr serviceName services;
	    servicePropertyListValue = getAttr servicePropertyList service;
	  in
	  filter (targetName:
	    let
	      target = getAttr targetName infrastructure;
	      targetPropertyValue = getAttr targetProperty target;
	    in
	      elem targetPropertyValue servicePropertyListValue
	  ) targets;
      }
    ) (attrNames distribution))
  ;
  
  mapAttrOnAttr = {distribution, services, infrastructure, serviceProperty, targetProperty}:
    listToAttrs (map (serviceName:
      { name = serviceName;
        value =
	  let
	    servicePropertyValue = getAttr serviceProperty (getAttr serviceName services);
	    targets = getAttr serviceName distribution;
	  in
	  filter (targetName:
	    let
	      targetPropertyValue = getAttr targetProperty (getAttr targetName infrastructure);
	    in
	    servicePropertyValue == targetPropertyValue
	  ) targets;
      }
    ) (attrNames distribution))
  ;
  
  mapStatefulToPrevious = {services, distribution, previousDistribution}:
    if previousDistribution == null then distribution
    else
    listToAttrs (map (serviceName:
      { name = serviceName;
        value =
          let
            service = getAttr serviceName services;
	    targets = getAttr serviceName distribution;
	    previousTargets = if hasAttr serviceName previousDistribution then getAttr serviceName previousDistribution
	                      else targets;
          in
          if service ? stateful && service.stateful then
	    filter (targetName: elem targetName previousTargets) targets
	  else targets;
      }
    ) (attrNames distribution))
  ;
}
{'fraction_non_alphanumeric': 0.06886045094454601, 'fraction_numerical': 0.0, 'mean_word_length': 2.8663133097762072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5131083', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1625, 'n_words': 471}