Questions tagged [equatable]

The Swift equatable protocol can be used to have objects use the equality operators for comparison.

144 questions
2
votes
1 answer

With a dart class that has a parameter of type list, how is it possible to make it equatable

I'm playing around with the new library bloc_test for flutter and I implemented the following test blocTest('should return ReservationsLoadSucess when the use case returns a list of reservationsList', build: () { …
2
votes
3 answers

Avoid Equatable and Hashable boilerplate, Swift 4.2

On project we are using classes for model's layer and because of that I have to write code like this: // MARK: - Hashable extension Player: Hashable { static func == (lhs: Player, rhs: Player) -> Bool { return lhs.hashValue ==…
Bohdan Savych
  • 3,310
  • 4
  • 28
  • 47
2
votes
2 answers

Override Equatable and Hashable in Swift

Is there a way to override Equatable of NSManagedObject? I have a coredata dataset of 300k objects and I need to remove duplicates base on the object's business id. // Coredata NSManagedObject import Foundation import…
Unikorn
  • 1,140
  • 1
  • 13
  • 27
2
votes
0 answers

swift protocol Equatable: Exposing nonvalue aspects of Equatable types other than class identity is discouraged

I'm currently studying swift API on protocol Equatable, and have encountered the following phrase Exposing nonvalue aspects of Equatable types other than class identity is discouraged Could someone explain it to me what is really means?
Thor
  • 9,638
  • 15
  • 62
  • 137
2
votes
2 answers

Swift doesn't call my "==" operator overload when I extend CollectionType

I have a custom class (VotingOption) which inherits from NSManagedObject and sometimes I want to check if some voting options within an array are duplicates. I am trying to make my code as general as possible. This is what I did to extend the…
himura
  • 1,555
  • 3
  • 19
  • 30
1
vote
1 answer

Does the "equal" property in flutter freezed replace the need of Equatable?

The documentation: Whether to generate a ==/hashcode or not If null, picks up the default values from the project's build.yaml. If that value is null too, generates a ==/hashcode only if the class does not have a custom == Does this replace the…
Joel Broström
  • 3,530
  • 1
  • 34
  • 61
1
vote
2 answers

Referencing operator function '==' on 'Equatable' requires that 'Dictionary.Values' conform to 'Equatable'

I have a class that defines a dictionary: class InventoryDictionary : Equatable { var dictionary : [ U : V? ] = [:] static func ==(lhs: InventoryDictionary, rhs: InventoryDictionary) -> Bool { return …
clearlight
  • 12,255
  • 11
  • 57
  • 75
1
vote
1 answer

Mock class that implements another class which uses Equatable

I faced a problem while mocking a class for testing. The problem is my class extends euqatable. And when I try to mock it I see the warning: Don't implement classes that override "==". I'm searching for a solution that solves this warning without…
Alex Verbitski
  • 499
  • 3
  • 12
1
vote
1 answer

How do I clean up a complicated .map function?

Introduction: I am trying to get my head around how to update deeply nested data using Equatable and .copyWith methods and in doing so, I have made a complex .map function. Problem: Ideally, I would like to use some iterative functional programming…
1
vote
2 answers

Why get props using in class on dart?

I used equatable in flutter dart to generate some boilerplate codes. here is a class that generated some boilerplate code using equitable import 'package:equatable/equatable.dart'; class Task extends Equatable { final String title; bool?…
mishalhaneef
  • 672
  • 8
  • 29
1
vote
2 answers

Using swift protocols as Equatable argument

For example we have two simple protocols: protocol Container { var items: [Item] {get} } protocol Item { var name: String {get} } And we want to use a function that requires Item to be Equatable, like: extension Container { func…
Vladimir
  • 7,670
  • 8
  • 28
  • 42
1
vote
1 answer

Is there a way to compare unordered Lists with Equatable package in Flutter?

I createad a class Question that extends equatable: it has a property named "answers" which is a List of String of dimension 4. I would like to compare 2 questions that have the same answers, whose items are unordered. Any ideas on how to do it?…
Andi
  • 43
  • 9
1
vote
1 answer

How to compare List of Map(i.e List) in dart using equatable package?

I need to compare a list of map (i.e List < Map >) in dart using equatable for to be used inside a bloc state class. But the problem is that equatable seems to not compare that list of map properties. class WaterCartDetailState extends Equatable { …
BestOFBest
  • 43
  • 7
1
vote
0 answers

Flutter bloc accessing the previous state?

I'm confused why yielding a new state is not causing the state variable inside by bloc class to actually update. The value of state remains what I initialize it to despite mapping events to to functions that are yielding new states. For example if…
user2561417
  • 295
  • 4
  • 13
1
vote
2 answers

Flutter Bloc: Bloc Event: Equatable: Classes can only extends other classes

Playing around with Bloc in Flutter. In the Bloc event, I faced a problem regarding Equatable. At first, I cannot import equatable package: import 'package:equatable/equatable.dart'; The error says: "The part-of directive must be the only directive…