Basic
Learn about basic in fp-ts nonemptyarray
Code Editor
01-basic.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('NonEmptyArray basics', () => {
it('creates non-empty array', () => {
const result = createNonEmpty(1, [2, 3, 4])
expect(result).toEqual([1, 2, 3, 4])
expect(result.length).toBeGreaterThan(0)
})
it('safely gets head', () => {
const arr = NEA.of(42)
expect(safeHead(arr)).toBe(42)
})
it('safely gets last', () => {
const arr: NEA.NonEmptyArray<number> = [1, 2, 3, 4, 5]
expect(safeLast(arr)).toBe(5)
})
it('head and last same for single element', () => {
const arr = NEA.of(99)
expect(safeHead(arr)).toBe(99)
expect(safeLast(arr)).toBe(99)
})
})🧪
Ready to Test?
Click "Run Tests" to see how your code performs
Quick Tips
•Read the TODO comments in the code
•Use Reset to restore original code
•Check Solution if stuck
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