Skip to content

Commit

Permalink
fix sortBy failing on empty list of ords
Browse files Browse the repository at this point in the history
  • Loading branch information
vicrac authored and gcanti committed Dec 13, 2019
1 parent fb6fbcb commit a5aa3a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Extend1 } from './Extend'
import { FilterableWithIndex1 } from './FilterableWithIndex'
import { Foldable1 } from './Foldable'
import { FoldableWithIndex1 } from './FoldableWithIndex'
import { Predicate, Refinement } from './function'
import { Predicate, Refinement, identity } from './function'
import { FunctorWithIndex1 } from './FunctorWithIndex'
import { HKT } from './HKT'
import { Monad1 } from './Monad'
Expand Down Expand Up @@ -1107,7 +1107,7 @@ export function uniq<A>(E: Eq<A>): (as: Array<A>) => Array<A> {
* @since 2.0.0
*/
export function sortBy<A>(ords: Array<Ord<A>>): (as: Array<A>) => Array<A> {
return sort(ords.slice(1).reduce(getSemigroup<A>().concat, ords[0]))
return ords.length > 0 ? sort(ords.slice(1).reduce(getSemigroup<A>().concat, ords[0])) : identity
}

/**
Expand Down Expand Up @@ -1285,8 +1285,6 @@ export function difference<A>(E: Eq<A>): (xs: Array<A>, ys: Array<A>) => Array<A
return (xs, ys) => xs.filter(a => !elemE(a, ys))
}

const identity = <A>(a: A): A => a

/**
* @since 2.0.0
*/
Expand Down
2 changes: 2 additions & 0 deletions test/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ describe('Array', () => {
{ name: 'c', age: 2 },
{ name: 'b', age: 3 }
])

assert.equal(sortBy([])(persons), persons)
})

it('compact', () => {
Expand Down

0 comments on commit a5aa3a1

Please sign in to comment.