purescript-arrays
purescript-arrays copied to clipboard
generalizes `deleteBy` parameter type
This generalizes deleteBy
parameter without any implementation changes.
Current problem is that we must have actual value or a dummy of the type of array item while using deleteBy
:
type Id = Int
type ComplicatedRecord = { id :: Id, a :: String, b :: Boolean, c :: ... }
deleteById :: Id -> Array ComplicatedRecord -> Array ComplicatedRecord
deleteById id = ? -- cannot implement with `deleteBy` unless creating dummy value of ComplicatedRecord
This PR allows it like this:
deleteById :: Id -> Array ComplicatedRecord -> Array ComplicatedRecord
deleteById = deleteBy \id item -> id == item.id
I believe this PR is almost non-breaking, however, there is a slight possibility of breakage related to type inference things. I verified that the all of latest package-set items can be built with this change.
Alternative approach:
delete :: forall a. Eq a => a -> Array a -> Array a
delete x = deleteBy (eq x)
deleteBy :: forall a. (a -> Boolean) -> Array a -> Array a
deleteBy p xs = _
-- usage
deleteById :: Id -> Array _ -> Array _
deleteById id = deleteBy \item -> id == item.id
This has more clear signature similar to filter
and easy to understand but is a Breaking-change.
Checklist:
- [x] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
- [ ] Linked any existing issues or proposals that this pull request should close
- [ ] Updated or added relevant documentation
- [ ] Added a test for the contribution (if applicable)
I decided put this change as Other improvements rather than Breaking changes or New features. I'm not sure which category was most appropriate for this.