33 */
44import { Either , isLeft , left , right } from 'fp-ts/lib/Either'
55import { Predicate , Refinement } from 'fp-ts/lib/function'
6+ import { ReadonlyNonEmptyArray } from 'fp-ts/lib/ReadonlyNonEmptyArray'
7+ import { readonlyNonEmptyArray } from 'fp-ts'
68
79// -------------------------------------------------------------------------------------
810// Decode error
@@ -23,7 +25,7 @@ export interface ContextEntry {
2325 * @category Decode error
2426 * @since 1.0.0
2527 */
26- export interface Context extends ReadonlyArray < ContextEntry > { }
28+ export interface Context extends ReadonlyNonEmptyArray < ContextEntry > { }
2729
2830/**
2931 * @category Decode error
@@ -237,15 +239,8 @@ export function getContextEntry(key: string, decoder: Decoder<any, any>): Contex
237239/**
238240 * @since 1.0.0
239241 */
240- export function appendContext ( c : Context , key : string , decoder : Decoder < any , any > , actual ?: unknown ) : Context {
241- const len = c . length
242- const r = Array ( len + 1 )
243- for ( let i = 0 ; i < len ; i ++ ) {
244- r [ i ] = c [ i ]
245- }
246- r [ len ] = { key, type : decoder , actual }
247- return r
248- }
242+ export const appendContext = ( c : Context , key : string , decoder : Decoder < any , any > , actual ?: unknown ) : Context =>
243+ readonlyNonEmptyArray . snoc ( c , { key, type : decoder , actual } )
249244
250245function pushAll < A > ( xs : Array < A > , ys : Array < A > ) : void {
251246 const l = ys . length
0 commit comments