jfmengels/elm-review-simplify

Simplifications to add

Open

#2 opened on 2021年4月22日

GitHub で見る
 (27 comments) (5 reactions) (0 assignees)Elm (10 forks)github user discovery
enhancementhelp wanted

Repository metrics

Stars
 (22 stars)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド