list-extra icon indicating copy to clipboard operation
list-extra copied to clipboard

Proposal for push

Open ghivert opened this issue 7 years ago • 2 comments
trafficstars

Hi.

I'm often using something like

pushIn : List a -> a -> List a
pushIn list elem =
  elem :: list

to use it into pipelines

doSomethingWithElems : a -> List a -> List a
doSomethingWithElems myElem allMyElems =
  myElem
    |> doSomethingWithTheElem
    |> pushIn allMyElems

What do you think about it? It's the exact reverse of (::), but since flip is gone, I think it is worthwhile.

ghivert avatar Jul 13 '18 12:07 ghivert

I would personally prefer |> \elem -> elem :: allMyElems here. Just my two cents.

pzp1997 avatar Jul 13 '18 12:07 pzp1997

I dont think its really that useful. In these cases I do..

doSomethingWithElems : a -> List a -> List a
doSomethingWithElems myElem =
    (::) (dosomethingWithTheElem myElem)

Chadtech avatar Jul 14 '18 14:07 Chadtech