Remove mkThenElse and mkAlways
This commit is contained in:
parent
2b4fba3d03
commit
9a92f3fc35
|
@ -25,7 +25,7 @@ rec {
|
|||
# contains a _type attribute and a list of functions which are used to
|
||||
# evaluate this property. The content attribute is used to stack properties
|
||||
# on top of each other.
|
||||
#
|
||||
#
|
||||
# The optional functions which may be contained in the property attribute
|
||||
# are:
|
||||
# - onDelay: run on a copied property.
|
||||
|
@ -41,7 +41,7 @@ rec {
|
|||
# property and call the function `nul' on the final value which is not a
|
||||
# property. The stack is traversed in reversed order. The `op' function
|
||||
# should expect a property with a content which have been modified.
|
||||
#
|
||||
#
|
||||
# Warning: The `op' function expects only one argument in order to avoid
|
||||
# calls to mkProperties as the argument is already a valid property which
|
||||
# contains the result of the folding inside the content attribute.
|
||||
|
@ -225,45 +225,11 @@ rec {
|
|||
inherit content;
|
||||
};
|
||||
|
||||
# Create a "ThenElse" property which contains choices being chosen by
|
||||
# the evaluation of an "If" statement.
|
||||
isThenElse = attrs: (typeOf attrs) == "then-else";
|
||||
mkThenElse = attrs:
|
||||
assert attrs ? thenPart && attrs ? elsePart;
|
||||
__trace "Obsolete usage of mkThenElse, replace it by mkMerge."
|
||||
mkProperty {
|
||||
property = {
|
||||
_type = "then-else";
|
||||
onEval = val: throw "Missing mkIf statement.";
|
||||
inherit (attrs) thenPart elsePart;
|
||||
};
|
||||
content = mkNotdef;
|
||||
};
|
||||
|
||||
# Create an "Always" property removing/ ignoring all "If" statement.
|
||||
isAlways = attrs: (typeOf attrs) == "always";
|
||||
mkAlways = value:
|
||||
mkProperty {
|
||||
property = {
|
||||
_type = "always";
|
||||
onEval = p@{content, ...}: content;
|
||||
inherit value;
|
||||
};
|
||||
content = mkNotdef;
|
||||
};
|
||||
|
||||
mkAssert = assertion: message: content:
|
||||
mkIf
|
||||
(if assertion then true else throw "\nFailed assertion: ${message}")
|
||||
content;
|
||||
|
||||
# Remove all "If" statement defined on a value.
|
||||
rmIf = foldProperty (
|
||||
foldFilter isIf
|
||||
({content, ...}: content)
|
||||
id
|
||||
) id;
|
||||
|
||||
# Evaluate the "If" statements when either "ThenElse" or "Always"
|
||||
# statement is encountered. Otherwise it removes multiple If statements and
|
||||
# replaces them by one "If" statement where the condition is the list of all
|
||||
|
@ -274,8 +240,8 @@ rec {
|
|||
# in the attribute list and attrs.
|
||||
ifProps =
|
||||
foldProperty
|
||||
(foldFilter (p: isIf p || isThenElse p || isAlways p)
|
||||
# then, push the codition inside the list list
|
||||
(foldFilter (p: isIf p)
|
||||
# then, push the condition inside the list list
|
||||
(p@{property, content, ...}:
|
||||
{ inherit (content) attrs;
|
||||
list = [property] ++ content.list;
|
||||
|
@ -297,19 +263,7 @@ rec {
|
|||
mkIf condition content
|
||||
else
|
||||
let p = head list; in
|
||||
|
||||
# evaluate the condition.
|
||||
if isThenElse p then
|
||||
if condition then
|
||||
copyProperties content p.thenPart
|
||||
else
|
||||
copyProperties content p.elsePart
|
||||
# ignore the condition.
|
||||
else if isAlways p then
|
||||
copyProperties content p.value
|
||||
# otherwise (isIf)
|
||||
else
|
||||
evalIf content (condition && p.condition) (tail list);
|
||||
evalIf content (condition && p.condition) (tail list);
|
||||
in
|
||||
evalIf ifProps.attrs true ifProps.list;
|
||||
|
||||
|
|
Loading…
Reference in a new issue