Skip to content

Should findIndex return Maybe Number instead of failing with -1? #36

@sharkdp

Description

@sharkdp

Let me start by saying that I really like how head, tail and other functions in this module are safe by default (compared to Haskell). Considering this, it seems strange to me that findIndex (and three related functions) have the type

findIndex :: forall a. (a -> Boolean) -> [a] -> Number

and fail with -1. While this is technically not 'unsafe' behavior, the -1 should not be used as an array index. Right now, I don't see how the -1 value is useful other than signalling failure. For me, it would feel more natural if the type would simply be

findIndex :: forall a. (a -> Boolean) -> [a] -> Maybe Number

and failure would be indicated by Nothing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions