Skip to main content
Module

x/rambda/reduce-spec.ts

Faster and smaller alternative to Ramda
Go to Latest
File
import {reduce} from 'rambda'
describe('R.reduce', () => { it('happy', () => { const result = reduce<number, number>( (acc, elem) => { acc // $ExpectType number elem // $ExpectType number return acc + elem }, 1, [1, 2, 3] )
result // $ExpectType number })
it('with two types', () => { const result = reduce<number, string>( (acc, elem) => { acc // $ExpectType string elem // $ExpectType number
return `${acc}${elem}` }, 'foo', [1, 2, 3] )
result // $ExpectType string })
it('with index', () => { const result = reduce<number, number>( (acc, elem, i) => { acc // $ExpectType number elem // $ExpectType number i // $ExpectType number return acc + elem }, 1, [1, 2, 3] )
result // $ExpectType number })
it('fallback', () => { const result = reduce( (acc, val) => { acc // $ExpectType number return acc + val }, 1, [1, 2, 3] )
result // $ExpectType number })
it('fallback with index', () => { const result = reduce( (acc, val, i) => { acc // $ExpectType number i // $ExpectType number return acc + val }, 1, [1, 2, 3] )
result // $ExpectType number })
it('fallback with two types', () => { const result = reduce( (acc, val) => { acc // $ExpectType string return acc + val }, 'foo', [1, 2, 3] )
result // $ExpectType string })})