generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e221e5
commit e6f28e1
Showing
2 changed files
with
20 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export * from "fp-ts/Array"; | ||
|
||
/** | ||
* Update the first element in an array that satisfies a predicate | ||
* @param predicate - The predicate to satisfy | ||
* @param update - The update function | ||
*/ | ||
export const updateFirst = | ||
<A>(predicate: (a: A) => boolean, update: (a: A) => A) => | ||
(as: A[]): A[] => { | ||
return as.reduce((acc, a) => { | ||
if (predicate(a)) { | ||
acc.push(update(a)); | ||
return acc; | ||
} | ||
acc.push(a); | ||
return acc; | ||
}, [] as A[]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters