Skip to main content
Module

x/rambda/source/sortBy-spec.ts

Faster and smaller alternative to Ramda
Go to Latest
File
import {sortBy, pipe} from 'rambda'
interface Input { a: number,}
describe('R.sortBy', () => { it('passing type to sort function', () => { function fn(x: any): number { return x.a } function fn2(x: Input): number { return x.a }
const input = [{a: 2}, {a: 1}, {a: 0}] const result = sortBy(fn, input) const curriedResult = sortBy(fn2)(input)
result // $ExpectType { a: number; }[] curriedResult // $ExpectType Input[] result[0].a // $ExpectType number curriedResult[0].a // $ExpectType number }) it('passing type to sort function and list', () => { function fn(x: Input): number { return x.a }
const input: Input[] = [{a: 2}, {a: 1}, {a: 0}] const result = sortBy(fn, input) const curriedResult = sortBy(fn)(input)
result // $ExpectType Input[] curriedResult // $ExpectType Input[] result[0].a // $ExpectType number }) it('with R.pipe', () => { interface Obj { value: number, } const fn = pipe(sortBy<Obj>(x => x.value))
const result = fn([{value: 1}, {value: 2}]) result // $ExpectType Obj[] })})