# Simplify list compare logic

**URL:** <https://discourse.elm-lang.org/t/simplify-list-compare-logic/3167>\
**Category:** Learn\
**Created:** [February 18, 2019, 9:53am UTC](https://discourse.elm-lang.org/t/simplify-list-compare-logic/3167 "2019-02-18T09:53:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Libbum](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/libbum/32/1311_2.png) [@Libbum](https://discourse.elm-lang.org/u/Libbum)\
**Post date:** [February 18, 2019, 9:53am UTC](https://discourse.elm-lang.org/t/simplify-list-compare-logic/3167/1 "2019-02-18T09:53:46Z")

</div>

I’m sure this could be done better, so just wondering how you would compare all values in two lists, returning true if all values are the same.

My current solution:

```elm
secret = [3,4,5,1,3,6]
challenge = [3,4,5,1,3,6]

List.map2 (==) secret challenge |> List.all (\c -> c == True)
--> True

```

I’d like to just use the core, but examples using `List.Extra` or something else would be interesting for my education. Specifically, I think this may be a time I could use the `>>` operator, but I have trouble conceptualising its use.

---

<div class="post-metadata">

**Author:** ![dmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dmy/32/702_2.png) [@dmy](https://discourse.elm-lang.org/u/dmy)\
**Post date:** [February 18, 2019, 10:01am UTC](https://discourse.elm-lang.org/t/simplify-list-compare-logic/3167/2 "2019-02-18T10:01:07Z")

</div>

Isn’t comparing the lists directly the same?

In `elm repl`:

```auto
> secret = [3,4,5,1,3,6]
[3,4,5,1,3,6]
    : List number
> challenge = [3,4,5,1,3,6]
[3,4,5,1,3,6]
    : List number
> (secret == challenge)
True : Bool

> challenge = [3,4,5,1,3,5]
[3,4,5,1,3,5]
    : List number
> (secret == challenge)
False : Bool

```

(Note that parentheses are needed because of a bug in `elm repl` if I remember correctly)

Or did I miss something? Maybe you want another way as an exercise?

Also your solution won’t work if lists have a different length as `List.map2` ignores extra values:

```auto
> challenge = [3,4,5,1,3,6,7]
[3,4,5,1,3,6,7]
    : List number
> List.map2 (==) secret challenge |> List.all (\c -> c == True)
True : Bool

```

---

<div class="post-metadata">

**Author:** ![Libbum](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/libbum/32/1311_2.png) [@Libbum](https://discourse.elm-lang.org/u/Libbum)\
**Post date:** [February 18, 2019, 10:12am UTC](https://discourse.elm-lang.org/t/simplify-list-compare-logic/3167/3 "2019-02-18T10:12:22Z")

</div>

Hah! Of course it is! Sorry, I was looking for complexity where there shouldn’t have been.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [February 28, 2019, 10:12am UTC](https://discourse.elm-lang.org/t/simplify-list-compare-logic/3167/4 "2019-02-28T10:12:30Z")

</div>

Closed on February 28, 2019, 10:12am UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
