Skip to content

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

Merged
mununki merged 3 commits into
mainfrom
feat/Array_distinct
Apr 1, 2024
Merged

mununki merged 3 commits into
mainfrom
feat/Array_distinct

Conversation

@WooWan

@WooWan WooWan commented Mar 29, 2024 •

Copy link
Copy Markdown
Contributor

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

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

@mununki mununki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread src/Garter_Array.res Outdated
let distinct = (ar, ~id) =>
ar
->reduceU((Belt.Set.make(~id), list{}), ((seen, res), v) =>
let distinctBy = (type a, arr: array<a>, f) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: ar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

적용했습니다! e9d07ff

Comment thread src/Garter_Array.resi
*/
let frequencies: (array<'a>, ~id: Belt.Map.id<'a, 'b>) => Belt.Map.t<'a, int, 'b>

/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
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

Sponsor
SponsoredKunjungi sekarang
Promo