Hyperlinkv0.8.0-beta.28

Order

Order.mapInputconsteffect/Order.ts:444
<B, A>(f: (b: B) => A): (self: Order<A>) => Order<B>
<A, B>(self: Order<A>, f: (b: B) => A): Order<B>

Transforms an Order on type A into an Order on type B by providing a function that maps values of type B to values of type A.

When to use

Use when you need to adapt an Order to compare a larger value by one derived property.

Details

Applies the mapping function to both values before comparison. The mapping function should be pure and not have side effects so the ordering properties of the original order are preserved.

Example (Mapping Input)

import { Order } from "effect"

const byLength = Order.mapInput(Order.Number, (s: string) => s.length)

console.log(byLength("a", "bb")) // -1
console.log(byLength("bb", "a")) // 1
console.log(byLength("aa", "bb")) // 0
Source effect/Order.ts:4447 lines
export const mapInput: {
  <B, A>(f: (b: B) => A): (self: Order<A>) => Order<B>
  <A, B>(self: Order<A>, f: (b: B) => A): Order<B>
} = dual(
  2,
  <A, B>(self: Order<A>, f: (b: B) => A): Order<B> => make((b1, b2) => self(f(b1), f(b2)))
)
Referenced by 2 symbols