Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distinctBy를 추가하고 distinct를 변경합니다. #39

Merged
merged 3 commits into from
Apr 1, 2024

Conversation

WooWan
Copy link
Contributor

@WooWan WooWan commented Mar 29, 2024

배열 요소에 대해서 중복을 제거하기 위해서는 아래와 같이 사용할 수 있습니다.

let distinctPeople =
  people
  ->Garter.Array.distinct
  ->Belt.Array.map(p => p.name)
  ->Belt.Array.joinWith(", ")

특정 key에 대해서 중복을 제거하기 위해서 아래와 같이 사용할 수 있습니다.

//before
module NameComparator = Belt.Id.MakeComparableU({
  type t = grennie
  let cmp = (a: t, b: t) => Pervasives.compare(a.name, b.name)
})

let names =
  people
  ->Garter.Array.distinct(~id=module(NameComparator))
  ->Belt.Array.map(p => p.name)
  ->Belt.Array.joinWith(", ")
//after
let names =
  people
  ->Garter.Array.distinctBy(p => p.name)
  ->Belt.Array.map(p => p.name)
  ->Belt.Array.joinWith(", ")

@WooWan WooWan marked this pull request as draft March 29, 2024 08:20
@WooWan WooWan marked this pull request as ready for review March 29, 2024 08:28
@WooWan WooWan requested a review from mununki March 29, 2024 09:12
Copy link
Member

@mununki mununki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

훌륭합니다.
몇 가지 사소한 내용만 수정해주세요.

let distinct = (ar, ~id) =>
ar
->reduceU((Belt.Set.make(~id), list{}), ((seen, res), v) =>
let distinctBy = (type a, arr: array<a>, f) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

적용했습니다! e9d07ff

@@ -77,10 +77,15 @@ let indexBy: (array<'a>, 'a => 'b, ~id: Belt.Map.id<'b, 'c>) => Belt.Map.t<'b, '
*/
let frequencies: (array<'a>, ~id: Belt.Map.id<'a, 'b>) => Belt.Map.t<'a, int, 'b>

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: distinct와 순서를 바꾸면 좋겠습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Garter_Array.res에서는 distinct가 내부적으로 distinctBy를 사용하고 있어 distinctBy가 먼저 선언되어 있습니다. resi에서도 순서를 통일하는 것을 어떤가요?

NonEmpty의 distinct, distinctBy와 순서가 달라서라면 NonEmpty의 순서를 바꿔도 좋을 것 같습니다!

@mununki mununki merged commit 2be2bce into main Apr 1, 2024
@mununki mununki deleted the feat/Array_distinct branch April 1, 2024 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants