typelevel / typelevel/cats

some/many on Alternative

Open
#3,454 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

Haskell's Alternative has some/many defined as:

some v = (:) <$> v <*> many v
many v = some v <|> pure []

We couldn't add those because without laziness the simple thing doesn't terminate. However, now that we have Defer[F] we can actually write these methods:

  def listOf[A](fa: F[A])(implicit F: Defer[F]): F[List[A]] =
    combineK(map(nonEmptyListOf(fa)(_.toList)), pure(Nil))

  def nonEmptyListOf[A](fa: F[A])(implicit F: Defer[F]): F[NonEmptyList[A]] =
    map2(fa, F.defer(listOf(fa)))(NonEmptyList(_, _))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names Alternative and Defer and proposes listOf and nonEmptyListOf as the entry points; first locate those definitions in the Cats source. Check how existing Alternative operations are tested, then confirm the new methods are available with the intended deferred behavior and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.