# Why does reduce not work on logical OR

**URL:** <https://discourse.julialang.org/t/why-does-reduce-not-work-on-logical-or/28679>\
**Category:** New to Julia\
**Created:** [September 12, 2019, 6:51am UTC](https://discourse.julialang.org/t/why-does-reduce-not-work-on-logical-or/28679 "2019-09-12T06:51:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [September 12, 2019, 6:51am UTC](https://discourse.julialang.org/t/why-does-reduce-not-work-on-logical-or/28679/1 "2019-09-12T06:51:33Z")

</div>

Why does reduce not work on logical OR

```julia
julia> a = UInt8[0,2,4,0,5,6,0]
7-element Array{UInt8,1}:
 0x00
 0x02
 0x04
 0x00
 0x05
 0x06
 0x00

julia> b = map(x->x>0,a)
7-element Array{Bool,1}:
 0
 1
 1
 0
 1
 1
 0

julia> reduce(||,b)
ERROR: syntax: invalid identifier name "||"
Stacktrace:
 [1] top-level scope at REPL[27]:0

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 12, 2019, 6:56am UTC](https://discourse.julialang.org/t/why-does-reduce-not-work-on-logical-or/28679/2 "2019-09-12T06:56:50Z")

</div>

`||` and `&&` in julia are not normal functions. The reason for this is that they short circuit, and the only way to implement this without a macro is to have them not be a normal function. This has several consequences, including this. The other main one is that you can’t define a function called `||` that does something different. As a solution, you could define`function or(a,b) =a||b end`, which should achieve what you want. However, you also could probably use `any` which will probably be faster.

---

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [September 12, 2019, 7:19am UTC](https://discourse.julialang.org/t/why-does-reduce-not-work-on-logical-or/28679/3 "2019-09-12T07:19:47Z")

</div>

Besides the syntax error, IIRC reduce will assume the order of the collection is not important.  
Maybe foldl is what you expect.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 12, 2019, 8:23am UTC](https://discourse.julialang.org/t/why-does-reduce-not-work-on-logical-or/28679/4 "2019-09-12T08:23:41Z")

</div>

You can use `|`

```julia
julia> b = [0,2,4,0,5,6,0] .> 0;

julia> reduce(|, b)
true

julia> reduce(&, b)
false

```

Or maybe it should be `foldl`, as @thautwarm suggests?
