Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tsfoster/elm-compare
DSL for building compare functions
https://github.com/tsfoster/elm-compare
comparable dsl elm elm-lang
Last synced: 2 months ago
JSON representation
DSL for building compare functions
- Host: GitHub
- URL: https://github.com/tsfoster/elm-compare
- Owner: TSFoster
- License: mit
- Created: 2017-02-24T00:26:45.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-09T22:02:46.000Z (over 5 years ago)
- Last Synced: 2024-10-12T20:21:07.630Z (2 months ago)
- Topics: comparable, dsl, elm, elm-lang
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/TSFoster/elm-compare/latest/
- Size: 30.3 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-compare
DSL for creating comparison functions in [Elm][elmlang].
[elmlang]: http://elm-lang.org/
## Usage
Install the package:
```shell
elm package install TSFoster/elm-compare
```Comparing records:
```elm
import Compare exposing (thenBy, thenByReverse, ascending, descending)winner =
let
compare : Player -> Player -> Basics.Order
compare =
Compare.by .pokerSkill thenBy .cardShufflingAbility ascending
in
case compare player opponent of
EQ ->
Nothing
LT ->
Just opponent
GT ->
Just playerrankings =
List.sortWith
(Compare.with rockPaperScissors thenBy .age descending)
allPlayersaddressBook =
List.sortWith
(Compare.by .lastName thenBy .firstName thenByReverse .dateOfBirth ascending)
allContacts
```For full documentation, see [package.elm-lang.org][package-doc].
[package-doc]: http://package.elm-lang.org/packages/TSFoster/elm-compare/latest
# [Tests](/tests)
```shell
git clone https://github.com/TSFoster/elm-compare.git
cd elm-compare
elm-test
npm install -g elm-doc-test && elm-doc-test && elm-test tests/Doc/Main.elm
```# License
[MIT](/LICENSE)