Module

Matrix

Package
purescript-matrices
Repository
kritzcreek/purescript-matrices

#Matrix Source

newtype Matrix a

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

Instances

#height Source

height :: forall a. Matrix a -> Int

Returns the height of a matrix.

#width Source

width :: forall a. Matrix a -> Int

Returns the width of a matrix.

#repeat Source

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"

#fromArray Source

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

#get Source

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

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

#getRow Source

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

Get the row at the given index.

#getColumn Source

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

Get the column at the given index.

#rows Source

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

Get all the rows in the matrix

#columns Source

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

Get all the columns in the matrix

#prettyPrintMatrix Source

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

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

#empty Source

empty :: forall a. Matrix a

The empty Matrix.

#isEmpty Source

isEmpty :: forall a. Matrix a -> Boolean

Checks whether a Matrix is empty

#set Source

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.

#modify Source

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.

#toIndexedArray Source

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

Convert a Matrix to an indexed Array

#indexedMap Source

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

#zipWith Source

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