Skip to content

Commit

Permalink
add Refinement overload to findFirst
Browse files Browse the repository at this point in the history
  • Loading branch information
wmaurer authored and gcanti committed Jan 6, 2021
1 parent 310628a commit d32a4d5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/Lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,13 @@ export function traverse<T extends URIS>(T: Traversable1<T>): <S, A>(sta: Lens<S
* @category combinators
* @since 2.3.2
*/
export const findFirst: <A>(predicate: Predicate<A>) => <S>(sa: Lens<S, ReadonlyArray<A>>) => Optional<S, A> =
/*#__PURE__*/
flow(_.findFirst, composeOptional)
export function findFirst<A, B extends A>(
refinement: Refinement<A, B>
): <S>(sa: Lens<S, ReadonlyArray<A>>) => Optional<S, B>
export function findFirst<A>(predicate: Predicate<A>): <S>(sa: Lens<S, ReadonlyArray<A>>) => Optional<S, A>
export function findFirst<A>(predicate: Predicate<A>): <S>(sa: Lens<S, ReadonlyArray<A>>) => Optional<S, A> {
return flow(_.findFirst, composeOptional)(predicate)
}

// -------------------------------------------------------------------------------------
// pipeables
Expand Down
10 changes: 7 additions & 3 deletions src/Optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,13 @@ export function traverse<T extends URIS>(T: Traversable1<T>): <S, A>(sta: Option
* @category combinators
* @since 2.3.2
*/
export const findFirst: <A>(predicate: Predicate<A>) => <S>(sa: Optional<S, ReadonlyArray<A>>) => Optional<S, A> =
/*#__PURE__*/
flow(_.findFirst, compose)
export function findFirst<A, B extends A>(
refinement: Refinement<A, B>
): <S>(sa: Optional<S, ReadonlyArray<A>>) => Optional<S, B>
export function findFirst<A>(predicate: Predicate<A>): <S>(sa: Optional<S, ReadonlyArray<A>>) => Optional<S, A>
export function findFirst<A>(predicate: Predicate<A>): <S>(sa: Optional<S, ReadonlyArray<A>>) => Optional<S, A> {
return flow(_.findFirst, compose)(predicate)
}

// -------------------------------------------------------------------------------------
// pipeables
Expand Down
10 changes: 7 additions & 3 deletions src/Prism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,13 @@ export function traverse<T extends URIS>(T: Traversable1<T>): <S, A>(sta: Prism<
* @category combinators
* @since 2.3.2
*/
export const findFirst: <A>(predicate: Predicate<A>) => <S>(sa: Prism<S, ReadonlyArray<A>>) => Optional<S, A> =
/*#__PURE__*/
flow(_.findFirst, composeOptional)
export function findFirst<A, B extends A>(
refinement: Refinement<A, B>
): <S>(sa: Prism<S, ReadonlyArray<A>>) => Optional<S, B>
export function findFirst<A>(predicate: Predicate<A>): <S>(sa: Prism<S, ReadonlyArray<A>>) => Optional<S, A>
export function findFirst<A>(predicate: Predicate<A>): <S>(sa: Prism<S, ReadonlyArray<A>>) => Optional<S, A> {
return flow(_.findFirst, composeOptional)(predicate)
}

// -------------------------------------------------------------------------------------
// pipeables
Expand Down

0 comments on commit d32a4d5

Please sign in to comment.