# How to pass values down the pipe sequence?

**URL:** https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619
**Category:** Learn
**Created:** [November 6, 2019, 5:29pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619 "2019-11-06T17:29:54Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kgashok](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/kgashok/32/1847_2.png) [@kgashok](https://discourse.elm-lang.org/u/kgashok)
#### Post date: [November 6, 2019, 5:29pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619/1 "2019-11-06T17:29:54Z")

</div>

```auto
renderList2 : List Int -> Int -> Html msg
renderList2 lst limit =
  let 
    attrBool x = if x > limit then True else False 
  in 
    lst
        |> List.map (\i -> (String.fromInt i ++ ", "))
        |> List.map (span [classList [("numberRed", True)] ] << List.singleton << text)
        |> ul []

```

How do I pass the value of `i` to `attrBool x` so that the `attrBool` is `True` only when `i` \> `limit`?

---

<div class="post-metadata">

### Author: ![jfmengels](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jfmengels/32/3124_2.png) [@jfmengels](https://discourse.elm-lang.org/u/jfmengels)
#### Post date: [November 6, 2019, 5:43pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619/2 "2019-11-06T17:43:32Z")

</div>

In this case, you can do a single `List.map` for the transformation to a string and the transformation to a `span`. If you do these two operations in the same function, then you keep access to `i`.  
Here is what I mean in code:

```elm
renderList2 : List Int -> Int -> Html msg
renderList2 lst limit =
  let 
    attrBool x = if x > limit then True else False 
  in 
    lst
        |> List.map (\i -> span [classList [("numberRed", attrBool i)] ] [text (String.fromInt i ++ ", ")])
        |> ul []

```

---

<div class="post-metadata">

### Author: ![Atlewee](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/atlewee/32/4603_2.png) [@Atlewee](https://discourse.elm-lang.org/u/Atlewee)
#### Post date: [November 6, 2019, 11:10pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619/3 "2019-11-06T23:10:16Z")

</div>

You may know, but a tip if that is not the case… the if statement can also be done inline:

```auto
renderList2 : List Int -> Int -> Html msg
renderList2 lst limit =
    lst
        |> List.map (\i -> span [classList [("numberRed", i > limit )] ] [text (String.fromInt i ++ ", ")])
        |> ul []

```

---

<div class="post-metadata">

### Author: ![kgashok](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/kgashok/32/1847_2.png) [@kgashok](https://discourse.elm-lang.org/u/kgashok)
#### Post date: [November 7, 2019, 1:42pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619/4 "2019-11-07T13:42:58Z")

</div>

Yes, thanks for that tip. I used it.

---

<div class="post-metadata">

### Author: ![kgashok](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/kgashok/32/1847_2.png) [@kgashok](https://discourse.elm-lang.org/u/kgashok)
#### Post date: [November 7, 2019, 1:44pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619/5 "2019-11-07T13:44:40Z")

</div>

But what if I want the value **`i`** to propagate down the pipeline, is it even possible?

---

<div class="post-metadata">

### Author: ![jfmengels](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jfmengels/32/3124_2.png) [@jfmengels](https://discourse.elm-lang.org/u/jfmengels)
#### Post date: [November 7, 2019, 2:15pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619/6 "2019-11-07T14:15:39Z")

</div>

It is possible, but you would have to be explicit about it. Basically, at every step of the pipeline, you’d return something (like a tuple), that contains `i` and the value you actually want to work on. Here is an example using a tuple:

```elm
renderList2 : List Int -> Int -> Html msg
renderList2 lst limit =
  let 
    attrBool x = if x > limit then True else False 
  in 
    lst
        |> List.map (\i -> (i, String.fromInt i ++ ", ")) -- Return a tuple
        |> List.map (\(i, intAsText) -> -- Deconstructing the tuple
            span [classList [("numberRed", attrBool i)] ] [text intAsText]
        )
        |> ul []

```

---

<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: [November 17, 2019, 2:29pm UTC](https://discourse.elm-lang.org/t/how-to-pass-values-down-the-pipe-sequence/4619/7 "2019-11-17T14:29:41Z")

</div>

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