Module

# Matrix

Package
purescript-matrices
Repository
kritzcreek/purescript-matrices

### #MatrixSource

``newtype Matrix a``

A two-dimensional Matrix. Its Show instance is meant as a tool for debugging/pretty-printing.

#### Instances

• `(Show a) => Show (Matrix a)`
• `(Eq a) => Eq (Matrix a)`
• `Functor Matrix`
• `Foldable Matrix`
• `Traversable Matrix`

### #heightSource

``height :: forall a. Matrix a -> Int``

Returns the height of a matrix.

### #widthSource

``width :: forall a. Matrix a -> Int``

Returns the width of a matrix.

### #repeatSource

``repeat :: forall a. Int -> Int -> a -> Matrix a``

Repeats the same value and creates a width × height `Matrix`.

``````> repeat 2 3 "X"
"X", "X"
"X", "X"
"X", "X"
``````

### #fromArraySource

``fromArray :: forall a. Array (Array a) -> Maybe (Matrix a)``

Constructs a Matrix from an Array of Arrays. Returns `Nothing` if the dimensions don't line up.

``````> fromMaybe empty (fromArray [[1,2,3], [4,5,6]])
1, 2, 3
4, 5, 6

> fromArray [[1,2,3], [4,5]]
Nothing
``````

### #getSource

``get :: forall a. Int -> Int -> Matrix a -> Maybe a``

Returns the value at column, row or `Nothing` if the index was out of bounds.

### #getRowSource

``getRow :: forall a. Int -> Matrix a -> Maybe (Array a)``

Get the row at the given index.

### #getColumnSource

``getColumn :: forall a. Int -> Matrix a -> Maybe (Array a)``

Get the column at the given index.

### #rowsSource

``rows :: forall a. Matrix a -> Array (Array a)``

Get all the rows in the matrix

### #columnsSource

``columns :: forall a. Matrix a -> Array (Array a)``

Get all the columns in the matrix

### #prettyPrintMatrixSource

``prettyPrintMatrix :: forall a. (a -> String) -> Matrix a -> String``

Pretty prints a matrix using the given formatting function on every element

### #emptySource

``empty :: forall a. Matrix a``

The empty Matrix.

### #isEmptySource

``isEmpty :: forall a. Matrix a -> Boolean``

Checks whether a Matrix is empty

### #setSource

``set :: forall a. Int -> Int -> a -> Matrix a -> Maybe (Matrix a)``

Sets the value at column, row or returns `Nothing` if the index was out of bounds.

### #modifySource

``modify :: forall a. Int -> Int -> (a -> a) -> Matrix a -> Maybe (Matrix a)``

Applies the given function to the element at column, row or returns Nothing if the index was out of bounds.

### #toIndexedArraySource

``toIndexedArray :: forall a. Matrix a -> Array { value :: a, x :: Int, y :: Int }``

Convert a `Matrix` to an indexed Array

### #indexedMapSource

``indexedMap :: forall b a. (Int -> Int -> a -> b) -> Matrix a -> Matrix b``

Apply a function to every element in the given Matrix taking its indices into account

### #zipWithSource

``zipWith :: forall c b a. (a -> b -> c) -> Matrix a -> Matrix b -> Maybe (Matrix c)``

Combines two Matrices with the same dimensions by combining elements at the same index with the given function. Returns Nothing on a dimension mismatch.

Modules
Matrix