jfmengels/elm-review-simplify

Simplifications to add

Open

#2 建立於 2021年4月22日

在 GitHub 查看
 (27 留言) (5 反應) (0 負責人)Elm (10 fork)github user discovery
enhancementhelp wanted

倉庫指標

Star
 (22 star)
PR 合併指標
 (PR 指標待抓取)

描述

Here are some of the simplifications I'd like to support.

If you'd like to work on some of these, please reply in a comment! If you want to suggest new ones, please open a new issue.

List

-- Possible but potentially quite ugly
List.foldl f x [ a ]
--> f (a) x

-- Only if acc is referenced only once
List.foldr (\a acc -> ... a :: acc) []
--> List.map (\a -> ... a)

List.drop n (List.drop m list)
--> List.drop (Basics.max 0 n + Basics.max 0 m) list -- Skip Basics.max if possible

List.take n (List.take m list)
--> List.take (Basics.max 0 (Basics.min n m)) list -- Skip Basics.min/max if possible

-- Only if n >= 1
list
  |> List.take n
  |> List.head
-->
list
  |> List.head

-- Possible but potentially quite ugly
list
  |> List.partition f
  |> Tuple.second
-->
list
  |> List.filter (f >> not) -- if we can insert a `not` in a nice way, that'd be cool!

list
  |> List.indexedMap Tuple.pair -- or equivalent lambda
  |> List.map Tuple.second
--> list

Set

-- Possible but potentially quite ugly
Set.foldl f x (Set.singleton a)
--> f a x

Maybe

-- ???
Maybe.andThen (f >> Maybe.map g) x
--> (Maybe.andThen (f) >> Maybe.map g) x

貢獻者指南