Skip to content

Syntax sugar to test equality #758

@ryanprior

Description

@ryanprior

I find myself writing this kind of function a lot:

let kind = "target kind"
records |> Array.select((record : MyRecordType) { record.kind == kind })

If we had a syntax sugar such as: .property=(val, type) then I could clarify it as such:

records |> Array.select(.kind=(kind, MyRecordType))

More general solution: function composition operator?

If we had a function composition operator (suppose we call it ||>) and a generic equality function (suppose it's Object.eq) then I could rewrite the function as:

records |> Array.select(.kind(MyRecordType) ||> Object.eq(kind))

...which is almost as nice as the syntax sugar, and much more general.

While I'm making wishes

Mint knows the type of records at compile-time: it's an Array(MyRecordType). That makes me think it could be possible to propagate that to .kind, making a hypothetical function real pithy:

records |> Array.select(.kind=(kind))
// or...
records |> Array.select(.kind ||> Object.eq(kind))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions