Tango-br
  • Introduction
  • Começando
    • Índice
    • Recado do desenvolvedor
    • O que é a Tango?
    • Por onde começar?
  • Instalação
    • Instalação via NuGet
    • Instalação manual
  • Conceitos
    • Introdução
    • Utilizando comparação de padrões (Pattern Matching)
    • Valores Opcionais
    • Valores "Ou um ou outro" (Either)
    • Saindo do void para o Unit
    • Delegates Func e Action
    • Utilizando operações encadeadas com processos contínuos
    • Currying e Aplicação Parcial
  • Funcional
    • Introdução
    • Currying
    • Aplicação Parcial
    • Extensões
    • Cast Rápido para Delegates
  • Operações
    • Introdução
    • Operações com Booleans
    • Operações com Inteiros
    • Operações com Decimais
    • Operações com Doubles
    • Operações com Strings
  • Tipos
    • Introdução
    • Unit
    • Option<T>
    • Either<TLeft, TRight>
    • Continuation<TFail, TSuccess>
  • Módulos
    • Introdução
    • Option
      • Apply
      • AsEnumerable
      • Bind
      • Count
      • Exists
      • Filter
      • Fold
      • FoldBack
      • Iterate
      • Map
      • OfNullable
      • ToArray
      • ToList
      • ToNullable
    • Either
      • Exists
      • Iterate
      • Fold
      • FoldBack
      • Map
      • Swap
      • ToTuple
    • Continuation
      • AsContinuation
      • Resolve
      • Reject
      • All
    • Collection
      • Append
      • Choose
      • ChunkBySize
      • Collect
      • CompareWith
      • CountBy
      • Concat
      • Distinct
      • Empty
      • Exists
      • Exists2
      • Filter
      • FindIndex
      • Fold
      • Fold2
      • FoldBack
      • FoldBack2
      • ForAll
      • ForAll2
      • ForAll3
      • Head
      • HeadAndTailEnd
      • Range
      • Generate
      • Initialize
      • Iterate
      • Iterate2
      • IterateIndexed
      • IterateIndexed2
      • Map
      • Map2
      • Map3
      • MapIndexed
      • MapIndexed2
      • MapIndexed3
      • Partition
      • Permute
      • Pick
      • Reduce
      • ReduceBack
      • Replicate
      • Scan
      • Scan2
      • ScanBack
      • ScanBack2
      • Tail
      • TryFind
      • TryPick
      • Unzip
      • Unzip3
      • Zip
      • Zip3
  • Extensões
    • Introdução
    • Extensões para Enum
    • Construtor de EqualityComparer
    • Módulos como extensão
Powered by GitBook
On this page

Was this helpful?

  1. Módulos
  2. Collection

Distinct

PreviousConcatNextEmpty

Last updated 5 years ago

Was this helpful?

Retorna a coleção sem elementos repetidos de acordo com os métodos comparer e hashCodeGetter.

Internamente este método utiliza o objeto .

Parâmetros

Retorno

Func<T, T, bool> comparer

Func<T, int> hashCodeGetter

IEnumerable<T> source

int

Como usar

Removendo elementos duplicados

class Product {
    int Id {get; set;}
    string Name {get; set;}
    double Price {get; set;}
}

// products:
// |    Id    |    Name    |    Price    |
// |    1     |  Notebook  |     800     |
// |    2     |    Mouse   |      20     |
// |    3     |   Wallet   |      40     |
// |    4     |    Book    |      10     |
// |    5     | Smartphone |     400     |
// |    1     |  Notebook  |     800     |
// |    1     |  Notebook  |     800     |
// |    4     |    Book    |      10     |

IEnumerable<Product> result = products.Distinct(
    (product1, product2) => product1.Id == product2 == Id,
     product => product.Id.GetHashCode()
    );

// result:
// |    Id    |    Name    |    Price    |
// |    1     |  Notebook  |     800     |
// |    2     |    Mouse   |      20     |
// |    3     |   Wallet   |      40     |
// |    4     |    Book    |      10     |
// |    5     | Smartphone |     400     |
EqualityComparerBuilder<T>