Skip to content

Commit

Permalink
Merge pull request #3 from TimonVS/chore/rename-matrix-functions
Browse files Browse the repository at this point in the history
Give Matrix functions more semantic names
  • Loading branch information
TimonVS authored May 22, 2019
2 parents ad90419 + e92a424 commit 45f6f0e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Fibonacci exposing (isFibonacci, isFibonacciSequence, isNextFibonacci)
import Html exposing (Html, button, div, table, td, text, tr)
import Html.Attributes exposing (class, style)
import Html.Events exposing (onClick)
import Matrix exposing (Matrix, Point, mapCells)
import Matrix exposing (Matrix, Point)
import Maybe
import Task
import Time
Expand Down Expand Up @@ -43,7 +43,7 @@ type alias Model =

init : () -> ( Model, Cmd msg )
init _ =
( Model (Matrix.createMatrix 50 50 ( Nothing, None )) (Time.millisToPosix 0), Cmd.none )
( Model (Matrix.repeat 50 50 ( Nothing, None )) (Time.millisToPosix 0), Cmd.none )



Expand Down Expand Up @@ -104,7 +104,7 @@ type Msg

incrementCells : Point -> Grid -> Grid
incrementCells ( x, y ) matrix =
mapCells
Matrix.map
(\cell ( colIndex, rowIndex ) ->
case cell of
( Just value, flag ) ->
Expand Down Expand Up @@ -147,7 +147,7 @@ lightUpFibonacciSequences grid =

resetFlags : Grid -> Grid
resetFlags matrix =
mapCells
Matrix.map
(\( value, flag ) _ ->
case ( value, flag ) of
( _, LightUpGreen ) ->
Expand Down
12 changes: 6 additions & 6 deletions src/Matrix.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Matrix exposing (Matrix, Point, createMatrix, mapCells)
module Matrix exposing (Matrix, Point, map, repeat)


type alias Matrix a =
Expand All @@ -9,13 +9,13 @@ type alias Point =
( Int, Int )


createMatrix : Int -> Int -> a -> Matrix a
createMatrix width height initialValue =
repeat : Int -> Int -> a -> Matrix a
repeat width height initialValue =
List.repeat height (List.repeat width initialValue)


mapCells : (a -> Point -> a) -> Matrix a -> Matrix a
mapCells fn matrix =
map : (a -> Point -> a) -> Matrix a -> Matrix a
map fn m =
List.indexedMap
(\rowIndex row ->
List.indexedMap
Expand All @@ -24,4 +24,4 @@ mapCells fn matrix =
)
row
)
matrix
m
4 changes: 2 additions & 2 deletions tests/MainTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ suite =
\_ ->
let
grid =
Matrix.createMatrix 3 3 ( Nothing, None )
Matrix.repeat 3 3 ( Nothing, None )
in
incrementCells ( 0, 0 ) grid
|> Expect.equal
Expand All @@ -27,7 +27,7 @@ suite =
\_ ->
let
grid =
Matrix.createMatrix 3 3 ( Nothing, None )
Matrix.repeat 3 3 ( Nothing, None )
in
incrementCells ( 0, 0 ) grid
|> incrementCells ( 1, 1 )
Expand Down
6 changes: 3 additions & 3 deletions tests/MatrixTests.elm
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module MatrixTests exposing (suite)

import Expect
import Matrix exposing (createMatrix)
import Matrix
import Test exposing (..)


suite : Test
suite =
describe "The Matrix module"
[ describe "createMatrix"
[ describe "Matrix.repeat"
[ test "create matrix of 3x3" <|
\_ ->
createMatrix 3 3 -1
Matrix.repeat 3 3 -1
|> Expect.equal
[ [ -1, -1, -1 ]
, [ -1, -1, -1 ]
Expand Down

0 comments on commit 45f6f0e

Please sign in to comment.