Skip to content

Syntax sugar to test equality #758

Closed

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))

Activity

  1. gdotdesign commented on Mar 31, 2025

    @gdotdesign
    Member

    Thanks for opening this issue 🙏

    I think it is a good opportunity for a helper function:

    fun mapEq(value : b, function: Function(a, b)) : Function(a, Bool) {
      (item : a) { function(item) == value }
    }
    
    records 
    |> Array.select(mapEq(kind, .kind(MyRecord)))
    |> Array.map(.kind(MyRecord))

    There could be a package with a module with a bunch of these helper functions.

    A working example here: https://mint-lang.com/sandbox/UPQfBJi5vWzNVA


    • Syntax sugar: Personally, I don't want to introduce more syntax sugars. I had/have a hard time understanding Haskell, and I'm afraid if we add more Mint will be hard to understand as well.
    • The type of field access (.kind) were optional before and basically was a syntax sugar for (item: {kind: a, ...}) { item.kind } and caused some type checking bugs. Maybe there is a way to make sure that we can resolve the type properly, I'll put in on the wishlist 🙂
  2. locked and limited conversation to collaborators on Jun 17, 2025
  3. converted this issue into a discussion #778 on Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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