Below is the list of all kinds of simplifications this rule applies.
Booleans
x || True
--> True
x || False
--> x
x && True
--> x
x && False
--> False
not True
--> False
x == True
--> x
x /= False
--> x
not x == not y
--> x == y
anything == anything
--> True
anything /= anything
--> False
not >> not
--> identity
If expressions
if True then x else y
--> x
if False then x else y
--> y
if condition then x else x
--> x
if condition then True else False
--> condition
if condition then False else True
--> not condition
Case expressions
case condition of
True -> x
False -> y
--> if condition then x else y
case condition of
False -> y
True -> x
--> if not condition then x else y
case value of
A _ -> x
B -> x
--> x
Basics functions
identity x
--> x
f >> identity
--> f
always x y
--> x
f >> always x
--> always x
Lambdas
(\\() -> x) data
--> x
(\\() y -> x) data
--> (\y -> x)
(\\_ y -> x) data
--> (\y -> x)
Operators
(++) a b
--> a ++ b
Numbers
n + 0
--> n
n - 0
--> n
0 - n
--> -n
n * 1
--> n
n * 0
--> 0
n / 1
--> n
-(-n)
--> n
negate >> negate
--> identity
Strings
"a" ++ ""
--> "a"
String.isEmpty ""
--> True
String.isEmpty "a"
--> False
String.concat []
--> ""
String.join str []
--> ""
String.join "" list
--> String.concat list
String.length "abc"
--> 3
String.repeat n ""
--> ""
String.repeat 0 str
--> ""
String.repeat 1 str
--> str
String.words ""
--> []
String.lines ""
--> []
Lists
a :: []
--> [ a ]
a :: [ b ]
--> [ a, b ]
[a] ++ list
--> a :: list
[] ++ list
--> list
[ a, b ] ++ [ c ]
--> [ a, b, c ]
[ a, b ] ++ [ c ]
--> [ a, b, c ]
List.concat []
--> []
List.concat [ [ a, b ], [ c ] ]
--> [ a, b, c ]
List.concat [ a, [ 1 ], [ 2 ] ]
--> List.concat [ a, [ 1, 2 ] ]
List.concatMap identity x
--> List.concat list
List.concatMap identity
--> List.concat
List.concatMap (\a -> a) list
--> List.concat list
List.concatMap fn [ x ]
--> fn x
List.concatMap (always []) list
--> []
List.map fn [] -- same for List.filter, List.filterMap, ...
--> []
List.map identity list
--> list
List.map identity
--> identity
List.filter (always True) list
--> list
List.filter (\a -> True) list
--> list
List.filter (always False) list
--> []
List.filter (always True)
--> identity
List.filter (always False)
--> always []
List.filterMap Just list
--> list
List.filterMap (\a -> Just a) list
--> list
List.filterMap Just
--> identity
List.filterMap (always Nothing) list
--> []
List.filterMap (always Nothing)
--> (always [])
List.isEmpty []
--> True
List.isEmpty [ a ]
--> False
List.isEmpty (x :: xs)
--> False
List.all fn []
--> True
List.all (always True) list
--> True
List.any fn []
--> True
List.any (always False) list
--> True
List.range 6 3
--> []
List.length [ a ]
--> 1
List.repeat n []
--> []
List.repeat 0 str
--> []
List.repeat 1 str
--> str
Sets
Set.map fn Set.empty -- same for Set.filter, ...
--> Set.empty
Set.map identity list
--> list
Set.map identity
--> identity
Cmd / Sub
All of these also apply for Sub.
Cmd.batch []
--> Cmd.none
Cmd.batch [ a ]
--> a
Cmd.batch [ a, Cmd.none, b ]
--> Cmd.batch [ a, b ]
Cmd.map identity cmd
--> cmd
Cmd.map fn Cmd.none
--> Cmd.none
Reports when an expression can be simplified.
Try it out
You can try this rule out by running the following command:
Simplifications
Below is the list of all kinds of simplifications this rule applies.
Booleans
If expressions
Case expressions
Basics functions
Lambdas
Operators
Numbers
Strings
Lists
Sets
Cmd / Sub
All of these also apply for
Sub.