Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-review-multiple-append-to-concat
elm-review: replace multiple `++` in sequence with concat
https://github.com/lue-bird/elm-review-multiple-append-to-concat
append concat elm elm-review plus-plus
Last synced: about 1 month ago
JSON representation
elm-review: replace multiple `++` in sequence with concat
- Host: GitHub
- URL: https://github.com/lue-bird/elm-review-multiple-append-to-concat
- Owner: lue-bird
- License: mit
- Created: 2023-08-11T10:02:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-02T21:22:16.000Z (10 months ago)
- Last Synced: 2024-10-19T05:31:54.122Z (2 months ago)
- Topics: append, concat, elm, elm-review, plus-plus
- Language: Elm
- Homepage: https://dark.elm.dmy.fr/packages/lue-bird/elm-review-multiple-append-to-concat/latest/
- Size: 96.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-review-multiple-append-to-concat
Provides the [`elm-review`](https://package.elm-lang.org/packages/jfmengels/elm-review/latest/) rule
[🔧`MultipleAppendToConcat`](https://package.elm-lang.org/packages/lue-bird/elm-review-multiple-append-to-concat/1.0.2/MultipleAppendToConcat/)
that replaces multiple `++` in sequence with concat, like```elm
combinedString =
"Your name is "
++ (nameParts
|> String.join " "
)
++ " and your age is "
++ (age |> String.fromInt)
++ "."
```
fixed to
```elm
combinedString =
String.concat
[ "Your name is "
, nameParts
|> String.join " "
, " and your age is "
, age |> String.fromInt
, "."
]
```and for lists
```elm
combinedList =
a
++ [ b, c ]
++ d
```
fixed to
```elm
combinedList =
List.concat
[ a
, [ b, c ]
, d
]
```- `elm-review` doesn't have type inference, so for values like `a ++ b ++ c` this rule doesn't provide a fix
- It is highly, highly recommended to use [`elm-review-simplify`](https://dark.elm.dmy.fr/packages/jfmengels/elm-review-simplify/latest/) alongside which simplifies
- `[ a, b ] ++ [ c, d ]` to `[ a, b, c, d ]`
- `[] ++ [ b, c ]` to `[ b, c ]`
- `[ a ] ++ b ++ c` to `a :: b ++ c` etc## why
#### it's more readable
This is somewhat subjective. Make sure everyone thinks the same before enabling the rule.
```elm
someDeclaration =
let
combinedList =
(a
++ ([ b, c ]
|> List.map .name
)
++ d
)
|> String.join ", "
in
...
```
vs
```elm
someDeclaration =
let
combinedList =
[ a
, [ b, c ]
|> List.map .name
, d
]
|> List.concat
|> String.join ", "
in
...
```#### less `appendable` and infix operators
`String.concat` and `List.concat` take concrete types and don't have the "magic-ness" of constrained type variables, operator precedence etc.## try it out
```bash
elm-review --template lue-bird/elm-review-multiple-append-to-concat/example
```If you like what it does, install it to your `review/` project and
## configure it
```elm
module ReviewConfig exposing (config)import MultipleAppendToConcat
import Review.Rule exposing (Rule)config : List Rule
config =
[ MultipleAppendToConcat.rule MultipleAppendToConcat.ApplyList
]
```