Effect CommunityEC
Effect Communityβ€’2w agoβ€’
5 replies
gheritt

Simplifying Option.liftPredicate Usage in Pipe

Very simple question. Say you have code like this:
  const max = pipe(
    [1, 2, 3, 4, 5] as Iterable<number>, // the type cast is just for example purposes to demonstarte starting a pipe with an iterable
    Array.fromIterable,
    (a) => Option.liftPredicate(Array.isNonEmptyReadonlyArray)(a),
    Option.map(Array.max(Order.number))
  )


Is there any better thing to do than the
(a) => Option.liftPredicate(Array.isNonEmptyReadonlyArray)(a)

?

By "better" I mean something that would avoid the lambda in the conversion from an Array<number> to an Option<NonEmptyReadonlyArray<number>>
Was this page helpful?