Remove mkThenElse and mkAlways
This commit is contained in:
parent
2b4fba3d03
commit
9a92f3fc35
@ -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 New Issue
Block a user