Git Product home page Git Product logo

Comments (14)

jgpacker avatar jgpacker commented on July 17, 2024

For ordered collections, we could also have a Sorted[A] predicate.
Though I'm not sure how the user could choose between ascendent and descendent order.

from refined.

fthomas avatar fthomas commented on July 17, 2024

Good idea, @jgpacker ! We could have SortedAsc and SortedDesc or provide an extra type for the sort order: trait SortOrder; trait Ascending extends SortOrder; trait Descending extends SortOrder. Another possibility is to have something like SortedWith[P] where P is some kind of binary predicate (which we don't have yet). For example: SortedWith[GreaterEqual2] where GreaterEqual2 gives you a BinaryPredicate instance with isValid(t1: T, t2: T): Boolean = t1 >= t2.

from refined.

fthomas avatar fthomas commented on July 17, 2024

Another collection predicate: IndexWhere[PA, PI]. It could be used like this IndexWhere[Digit, LessEqual[_2]] which validates any collection of Char where one of the first three chars is a digit.

from refined.

fthomas avatar fthomas commented on July 17, 2024
  • Contains[A]
  • Index[N, P]
  • Unique
  • Head[P]
  • Last[P]
  • Tail[P]
  • Init[P]

from refined.

fthomas avatar fthomas commented on July 17, 2024

SortedWith as outlined in #6 (comment) is a misnomer. It should better be called Pairwise[P] since it checks if consecutive pairs of elements in a sequence satisfy the binary predicate P.

from refined.

sh0hei avatar sh0hei commented on July 17, 2024

Hi, @fthomas :)

I want to Implement Unique Predicate.
I want you to tell me Signature of Unique and Usage of Unique.

from refined.

fthomas avatar fthomas commented on July 17, 2024

@sh0hei The idea of Unique is that it checks that a collection has no duplicated elements. It has no parameters, so would be defined as empty case class: case class Unique().

Usage would look something like this:

type UniqueList[A] = List[A] Refined Unique 

scala> RefType.applyRef[UniqueList[Int]](List(1, 2, 3))
res0: Either[String, UniqueList[Int]]= Right(Refined(List(1, 2, 3)))

scala>RefType.applyRef[UniqueList[Int]](List(1, 2, 2))
res1: Either[String, UniqueList[Int]]= Left("Predicate failed: List(1, 2, 2) contains duplicated elements: 2")

from refined.

sh0hei avatar sh0hei commented on July 17, 2024

okay :)
I try it !

from refined.

fthomas avatar fthomas commented on July 17, 2024

Awesome! :-)

from refined.

sh0hei avatar sh0hei commented on July 17, 2024

@fthomas Excuse me, I'd like also to know about Usage Tail, Init. I'll try to implement it.

from refined.

fthomas avatar fthomas commented on July 17, 2024

@sh0hei Tail and Init would be similar to the already existing Head and Last predicates (see collection.scala). They check if all but the first/last element of a sequence satisfy a given predicate.

from refined.

fthomas avatar fthomas commented on July 17, 2024

Closing since most of the predicates in this ticket are now implemented.

from refined.

kubukoz avatar kubukoz commented on July 17, 2024

Hey, what's the status on Sorted predicates?

from refined.

fthomas avatar fthomas commented on July 17, 2024

@kubukoz It hasn't been implemented yet. :) But I'm open to adding Sorted or Sorted{Asc, Desc} or something similar to the librarary.

from refined.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.