core icon indicating copy to clipboard operation
core copied to clipboard

[Consistency Review] APIs around `find`

Open peter-jerry-ye opened this issue 10 months ago • 3 comments

Currently, the functions related to find has different naming conventions and different semantics.

Operation that find the index using a given predicate

  • fn Array::search_by[T](self : Array[T], f : (T) -> Bool) -> Int?
  • fn Array::binary_search_by[T](self : Array[T], cmp : (T) -> Int) -> Result[Int, Int]
  • fn String::find_by(self : String, pred : (Char) -> Bool) -> Int?
  • fn View::find_by(self : View, pred : (Char) -> Bool) -> Int?
  • fn find[A](self : T[A], f : (A) -> Bool) -> A? // @immut/list
  • fn findi[A](self : T[A], f : (A, Int) -> Bool) -> A? // @immut/list

Operation that find the index using a given value

  • fn Array::search[T : Eq](self : Array[T], value : T) -> Int?
  • fn Array::binary_search[T : Compare](self : Array[T], value : T) -> Result[Int, Int]
  • fn FixedArray::search[T : Eq](self : FixedArray[T], value : T) -> Int?
  • fn String::find(self : String, str : View) -> Int?
  • fn View::find(self : View, str : View) -> Int?
  • fn search[A : Eq](self : T[A], value : A) -> Int? // @deque

Operation that find the given value using a given predicate

  • fn Iter::find_first[T](self : Iter[T], f : (T) -> Bool) -> T?

Operation that find the given value using a given key

  • fn lookup[A : Eq, B](self : T[(A, B)], v : A) -> B? // @imut/list

cc @bobzhang

peter-jerry-ye avatar Apr 24 '25 04:04 peter-jerry-ye

Additional notes:

Operation that find the given value using a given key

  • op_get
  • get

hackwaly avatar Apr 27 '25 08:04 hackwaly

We align to find and find_by.

peter-jerry-ye avatar May 09 '25 08:05 peter-jerry-ye

Would we introduce a new type SortedArray of Array? So that we can just use SortedArray::find and not use Array::binary_find.

hackwaly avatar May 11 '25 15:05 hackwaly