Can I remove the lambda from this Elma expression?

Here is a complete Elm script that puts a bunch of tuples in an HTML element <ul>.

import Html exposing (ul, li, text)
import List exposing (map)

values = [(1,2,3), (4,5,6), (7,8,9)]

main =
  ul [] (values |> map (\t -> li [] [text(toString(t))]))

I like to use |>other higher order operators where possible, but with relatively deep nesting tin the expression above, I could not find a good way to express this line. Are there higher order operators in Elm that would make lambda \tunnecessary?

I understand that it would be more readable to use lambda, but it was interesting what combinations should be used here, given that the call toStringis inside the list.

+4
source share
1 answer

If you want to avoid the lambda, it’s easier to start with valuesand the “pipeline”, rearranging it step by step to get it in the final form that you want:

import Html exposing (ul, li, text)
import List exposing (map, repeat)

values = [(1,2,3), (4,5,6), (7,8,9)]

main
  = map toString values
  |> map text
  |> map (repeat 1)
  |> map (li [])
  |> ul []
+6
source

Source: https://habr.com/ru/post/1625055/


All Articles