Created
January 18, 2016 21:24
-
-
Save jah2488/da3ef5c7cf755e9ef4ff to your computer and use it in GitHub Desktop.
Playing around with custom sorting on nested structures in Elm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Graphics.Element exposing (show) | |
| type State = Ready | Working | Complete | |
| stateSort a = | |
| case a.state of | |
| Ready -> 1 | |
| Working -> 2 | |
| Complete -> 3 | |
| type alias Row = | |
| { pos : Int | |
| , state : State | |
| } | |
| type alias Col = | |
| { rows : List Row | |
| , state : State | |
| } | |
| model = | |
| { | |
| cols = | |
| [ { state = Ready, rows = [] }, | |
| { state = Working, rows = [] }, | |
| { state = Complete, rows = [] }], | |
| rows = | |
| [ { pos = 2, state = Ready} | |
| , { pos = 7, state = Working} | |
| , { pos = 3, state = Ready } | |
| , { pos = 5, state = Complete } | |
| , { pos = 6, state = Ready } | |
| , { pos = 4, state = Working }]} | |
| partitionRows x = | |
| List.map (\col -> | |
| { state = col.state, | |
| rows = (List.sortBy .pos (List.filter (\r -> r.state == col.state) x.rows)) }) x.cols | |
| showPartitionedRows = partitionRows model | |
| |> show | |
| showSortedRows = rows | |
| |> List.sortBy .pos | |
| |> List.sortBy stateSort | |
| |> show | |
| main = showPartitionedRows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment