Operations

beginner3 of 6

Learn about operations in fp-ts nonemptyarray

Code Editor

03-operations.exercise.ts

💻
Loading editor...
Preparing Monaco Editor with TypeScript support

Test Results

Requirements

describe('NonEmptyArray operations', () => {
  it('maps over non-empty array', () => {
    const arr: NEA.NonEmptyArray<number> = [1, 2, 3]
    const result = mapNonEmpty(arr)
    expect(result).toEqual([2, 4, 6])
  })

  it('concatenates non-empty arrays', () => {
    const arr1: NEA.NonEmptyArray<number> = [1, 2]
    const arr2: NEA.NonEmptyArray<number> = [3, 4]
    const result = concatNonEmpty(arr1, arr2)
    expect(result).toEqual([1, 2, 3, 4])
  })

  it('concat preserves non-emptiness', () => {
    const arr1 = NEA.of(1)
    const arr2 = NEA.of(2)
    const result = concatNonEmpty(arr1, arr2)
    expect(result.length).toBeGreaterThan(0)
  })
})
🧪

Ready to Test?

Click "Run Tests" to see how your code performs

Pro Tips

💡 Stuck? Here's what to try:

  • • Read the comments in the code carefully
  • • Run tests frequently to get feedback
  • • Check the fp-ts documentation
  • • Use the solution if you need help

🚀 Learning Approach:

  • • Focus on understanding, not just solving
  • • Experiment with different approaches
  • • Think about real-world applications
  • • Build on previous exercises