mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Rename List.find and findIndex to include 'First'
This commit is contained in:
parent
661376958c
commit
f3b8025d8d
4 changed files with 17 additions and 17 deletions
|
@ -81,7 +81,7 @@ withCapacity = \n -> @Dict (List.withCapacity n)
|
||||||
|
|
||||||
get : Dict k v, k -> Result v [KeyNotFound]*
|
get : Dict k v, k -> Result v [KeyNotFound]*
|
||||||
get = \@Dict list, needle ->
|
get = \@Dict list, needle ->
|
||||||
when List.find list (\Pair key _ -> key == needle) is
|
when List.findFirst list (\Pair key _ -> key == needle) is
|
||||||
Ok (Pair _ v) ->
|
Ok (Pair _ v) ->
|
||||||
Ok v
|
Ok v
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ walk = \@Dict list, initialState, transform ->
|
||||||
|
|
||||||
insert : Dict k v, k, v -> Dict k v
|
insert : Dict k v, k, v -> Dict k v
|
||||||
insert = \@Dict list, k, v ->
|
insert = \@Dict list, k, v ->
|
||||||
when List.findIndex list (\Pair key _ -> key == k) is
|
when List.findFirstIndex list (\Pair key _ -> key == k) is
|
||||||
Err NotFound ->
|
Err NotFound ->
|
||||||
insertFresh (@Dict list) k v
|
insertFresh (@Dict list) k v
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ len = \@Dict list ->
|
||||||
|
|
||||||
remove : Dict k v, k -> Dict k v
|
remove : Dict k v, k -> Dict k v
|
||||||
remove = \@Dict list, key ->
|
remove = \@Dict list, key ->
|
||||||
when List.findIndex list (\Pair k _ -> k == key) is
|
when List.findFirstIndex list (\Pair k _ -> k == key) is
|
||||||
Err NotFound ->
|
Err NotFound ->
|
||||||
@Dict list
|
@Dict list
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ interface List
|
||||||
any,
|
any,
|
||||||
takeFirst,
|
takeFirst,
|
||||||
takeLast,
|
takeLast,
|
||||||
find,
|
findFirst,
|
||||||
findIndex,
|
findFirstIndex,
|
||||||
sublist,
|
sublist,
|
||||||
intersperse,
|
intersperse,
|
||||||
split,
|
split,
|
||||||
|
@ -774,8 +774,8 @@ joinMap = \list, mapper ->
|
||||||
|
|
||||||
## Returns the first element of the list satisfying a predicate function.
|
## Returns the first element of the list satisfying a predicate function.
|
||||||
## If no satisfying element is found, an `Err NotFound` is returned.
|
## If no satisfying element is found, an `Err NotFound` is returned.
|
||||||
find : List elem, (elem -> Bool) -> Result elem [NotFound]*
|
findFirst : List elem, (elem -> Bool) -> Result elem [NotFound]*
|
||||||
find = \array, pred ->
|
findFirst = \array, pred ->
|
||||||
callback = \_, elem ->
|
callback = \_, elem ->
|
||||||
if pred elem then
|
if pred elem then
|
||||||
Break elem
|
Break elem
|
||||||
|
@ -792,8 +792,8 @@ find = \array, pred ->
|
||||||
## Returns the index at which the first element in the list
|
## Returns the index at which the first element in the list
|
||||||
## satisfying a predicate function can be found.
|
## satisfying a predicate function can be found.
|
||||||
## If no satisfying element is found, an `Err NotFound` is returned.
|
## If no satisfying element is found, an `Err NotFound` is returned.
|
||||||
findIndex : List elem, (elem -> Bool) -> Result Nat [NotFound]*
|
findFirstIndex : List elem, (elem -> Bool) -> Result Nat [NotFound]*
|
||||||
findIndex = \list, matcher ->
|
findFirstIndex = \list, matcher ->
|
||||||
foundIndex = List.iterate list 0 \index, elem ->
|
foundIndex = List.iterate list 0 \index, elem ->
|
||||||
if matcher elem then
|
if matcher elem then
|
||||||
Break index
|
Break index
|
||||||
|
|
|
@ -1266,7 +1266,7 @@ define_builtins! {
|
||||||
42 LIST_TAKE_FIRST: "takeFirst"
|
42 LIST_TAKE_FIRST: "takeFirst"
|
||||||
43 LIST_TAKE_LAST: "takeLast"
|
43 LIST_TAKE_LAST: "takeLast"
|
||||||
44 LIST_FIND: "find"
|
44 LIST_FIND: "find"
|
||||||
45 LIST_FIND_RESULT: "#find_result" // symbol used in the definition of List.find
|
45 LIST_FIND_RESULT: "#find_result" // symbol used in the definition of List.findFirst
|
||||||
46 LIST_SUBLIST: "sublist"
|
46 LIST_SUBLIST: "sublist"
|
||||||
47 LIST_INTERSPERSE: "intersperse"
|
47 LIST_INTERSPERSE: "intersperse"
|
||||||
48 LIST_INTERSPERSE_CLOS: "#intersperseClos"
|
48 LIST_INTERSPERSE_CLOS: "#intersperseClos"
|
||||||
|
|
|
@ -2846,7 +2846,7 @@ fn list_find() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
when List.find ["a", "bc", "def"] (\s -> Str.countGraphemes s > 1) is
|
when List.findFirst ["a", "bc", "def"] (\s -> Str.countGraphemes s > 1) is
|
||||||
Ok v -> v
|
Ok v -> v
|
||||||
Err _ -> "not found"
|
Err _ -> "not found"
|
||||||
"#
|
"#
|
||||||
|
@ -2862,7 +2862,7 @@ fn list_find_not_found() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
when List.find ["a", "bc", "def"] (\s -> Str.countGraphemes s > 5) is
|
when List.findFirst ["a", "bc", "def"] (\s -> Str.countGraphemes s > 5) is
|
||||||
Ok v -> v
|
Ok v -> v
|
||||||
Err _ -> "not found"
|
Err _ -> "not found"
|
||||||
"#
|
"#
|
||||||
|
@ -2878,7 +2878,7 @@ fn list_find_empty_typed_list() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
when List.find [] (\s -> Str.countGraphemes s > 5) is
|
when List.findFirst [] (\s -> Str.countGraphemes s > 5) is
|
||||||
Ok v -> v
|
Ok v -> v
|
||||||
Err _ -> "not found"
|
Err _ -> "not found"
|
||||||
"#
|
"#
|
||||||
|
@ -2895,7 +2895,7 @@ fn list_find_empty_layout() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
List.find [] (\_ -> True)
|
List.findFirst [] (\_ -> True)
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
|
@ -2909,7 +2909,7 @@ fn list_find_index() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
when List.findIndex ["a", "bc", "def"] (\s -> Str.countGraphemes s > 1) is
|
when List.findFirstIndex ["a", "bc", "def"] (\s -> Str.countGraphemes s > 1) is
|
||||||
Ok v -> v
|
Ok v -> v
|
||||||
Err _ -> 999
|
Err _ -> 999
|
||||||
"#
|
"#
|
||||||
|
@ -2925,7 +2925,7 @@ fn list_find_index_not_found() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
when List.findIndex ["a", "bc", "def"] (\s -> Str.countGraphemes s > 5) is
|
when List.findFirstIndex ["a", "bc", "def"] (\s -> Str.countGraphemes s > 5) is
|
||||||
Ok v -> v
|
Ok v -> v
|
||||||
Err _ -> 999
|
Err _ -> 999
|
||||||
"#
|
"#
|
||||||
|
@ -2941,7 +2941,7 @@ fn list_find_index_empty_typed_list() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
when List.findIndex [] (\s -> Str.countGraphemes s > 5) is
|
when List.findFirstIndex [] (\s -> Str.countGraphemes s > 5) is
|
||||||
Ok v -> v
|
Ok v -> v
|
||||||
Err _ -> 999
|
Err _ -> 999
|
||||||
"#
|
"#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue