Code Monkey home page Code Monkey logo

elm-2d-array's People

Contributors

joshuahall avatar

Watchers

 avatar  avatar

Forkers

jxxcarlson

elm-2d-array's Issues

Array2D.get does not always return Nothing when it should

Hi!
I recently had a bug when searching for neighbours in an Array2D.
It looks like when calling Array2D.get with a negative column will return values from the previous row, if any, starting from the end.

array = Array2D.fromRows <|
    Array.fromList
        [ Array.fromList [ 1, 2 ]
        , Array.fromList [ 3, 4 ]
        ]

result = Maybe.map (Array.get 1 -1) array -- returns (Just 2) instead of Nothing

Please see the following Ellie: https://ellie-app.com/gbCSDCn2r9ka1

Is it intended behaviour?

[EDIT]

If is not intended behaviour, I guess I could add a check against row/column begin greater than numRows/numColumns here:

get : Int -> Int -> Array2D a -> Maybe a
get row column (InternalArray2D array) =
    if row >= array.numRows || column >= array.numColumns then
        Nothing

    else
        Array.get
            (indexFromRowAndColumn (InternalArray2D array) row column)
            array.array

Array2D.initialize: in the provided function row and column indices are wrong

In the first example indices are correct in the provided function, but in the second example, you can see that the indices are wrong.
I think the problem occurs when rows are greater than cols.

Array2D.initialize 4 4 (\row col -> (String.fromInt row ++ ":" ++ String.fromInt col))
["0:0","0:1","0:2","0:3"
,"1:0","1:1","1:2","1:3"
,"2:0","2:1","2:2","2:3"
,"3:0","3:1","3:2","3:3"
]

Array2D.initialize 4 2 (\row col -> (String.fromInt row ++ ":" ++ String.fromInt col))
["0:0","0:1"
,"0:0","0:1"
,"1:0","1:1"
,"1:0","1:1
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.