haskell - Evaluating and gathering results of conditions -
i have bunch of conditions returns lists, there way of evaluating them without giving each condition name?
simplified example:
conditions j = c1 j ++ c2 j ++ c3 j c1 j | > 2 = ["x"] | otherwise = [] c2 j | j > 5 = ["y", "a"] | otherwise = [] c3 j | j > 10 = ["z"] | otherwise = [] c4 j | j > 10 && > 1 = ["z", "c", "hello"] | otherwise = []
you can define operator this:
infixl 1 *| (*|) :: [a] -> bool -> [a] xs *| b | b = xs xs *| b = [] conditions j = (["x"] *| > 2) ++ (["y", "a"] *| j > 5) ++ (["z"] *| j > 10) ++ (["z","c","hello"] *| j > 10 && > 1)
it'a possible rewrite last line as
++ (["z","c","hello"] *| j > 10 *| > 1)
if desired reason.
Comments
Post a Comment