{"record":{"id":"157750ff6736da94","repo":"louthy/language-ext","slug":"foldback-is-currently-not-supported-for-iterablene","errorCode":null,"errorMessage":"FoldBack* is currently not supported for IterableNE","messagePattern":"FoldBack\\* is currently not supported for IterableNE","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Immutable Collections/IterableNE/Trait/IterableNE.TraitImpl.cs","lineNumber":54,"sourceCode":"    static K<IterableNE, B> Applicative<IterableNE>.Apply<A, B>(K<IterableNE, Func<A, B>> mf, Memo<IterableNE, A> ma) =>\n        mf >> ma.Map;\n\n    static K<IterableNE, A> SemigroupK<IterableNE>.Combine<A>(K<IterableNE, A> ma, K<IterableNE, A> mb) =>\n        ma.As().Concat(mb.As());\n    \n    static S Foldable<IterableNE>.FoldWhile<A, S>(\n        Func<A, Func<S, S>> f,\n        Func<(S State, A Value), bool> predicate,\n        S state,\n        K<IterableNE, A> ta) =>\n        ta.As().FoldWhile(f, predicate, state);\n    \n    static S Foldable<IterableNE>.FoldBackWhile<A, S>(\n        Func<S, Func<A, S>> f, \n        Func<(S State, A Value), bool> predicate, \n        S state, \n        K<IterableNE, A> ta) =>\n        throw new NotSupportedException(\"FoldBack* is currently not supported for IterableNE\");\n    \n    static Arr<A> Foldable<IterableNE>.ToArr<A>(K<IterableNE, A> ta) =>\n        new(ta.As());\n\n    static Lst<A> Foldable<IterableNE>.ToLst<A>(K<IterableNE, A> ta) =>\n        new(ta.As());\n\n    static Iterable<A> Foldable<IterableNE>.ToIterable<A>(K<IterableNE, A> ta) =>\n        ta.As().AsIterable();\n    \n    static Seq<A> Foldable<IterableNE>.ToSeq<A>(K<IterableNE, A> ta) =>\n        new(ta.As());\n\n    static K<Seq, A> Natural<IterableNE, Seq>.Transform<A>(K<IterableNE, A> fa) => \n        toSeq(fa.As());\n\n    static K<Arr, A> Natural<IterableNE, Arr>.Transform<A>(K<IterableNE, A> fa) => \n        toArray(fa.As());","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Immutable Collections/IterableNE/Trait/IterableNE.TraitImpl.cs#L36-L72","documentation":"IterableNE (non-empty iterable) implements Foldable but its FoldBackWhile (and other FoldBack*) trait members are not implemented; they unconditionally throw NotSupportedException. This is a deliberate library gap, not a bug in your code — backward folding over IterableNE has no implementation yet.","triggerScenarios":"Calling FoldBackWhile, FoldBack, FoldBackT or any FoldBack* operation with the Foldable<IterableNE> instance, e.g. `xs.FoldBackWhile(f, pred, state)` where xs is an IterableNE<A>.","commonSituations":"Generic foldable code written against IEnumerable or Lst that gets reused on IterableNE; switching a data structure from Lst/Seq to IterableNE in generic fold pipelines; expecting feature parity between forward folds and backward folds.","solutions":["Use the forward-fold equivalents instead: FoldWhile / Fold on the same IterableNE value.","Convert to a structure with full Foldable support first, e.g. `xs.ToLst()` or `xs.ToArr()`, then fold back over that.","If you truly need backward folding in place, accumulate via Fold into a reversed structure or supply your own fold-back helper over ToArr()."],"exampleFix":"// before\nvar sum = xs.FoldBackWhile(s => a => s + a, x => x < 10, 0);\n// after\nvar sum = xs.FoldWhile(s => a => s + a, x => x < 10, 0);","handlingStrategy":"fallback","validationCode":"// Feature-check before use (NotSupportedException is thrown unconditionally for FoldBack* on IterableNE)\nvar canFoldBack = xs is not IterableNE<A>; // for IterableNE use FoldWhile or convert first","typeGuard":"static bool SupportsFoldBack<A>(K<IterableNE, A> _) => false; // FoldBack* is never supported on IterableNE","tryCatchPattern":"try { result = xs.FoldBackWhile(f, pred, state); }\ncatch (NotSupportedException) { result = xs.FoldWhile(f, pred, state); }","preventionTips":["Prefer Fold/FoldWhile on IterableNE; reserve FoldBack for structures that implement it (Lst, Arr, Seq).","Wrap generic foldable algorithms in a small abstraction that picks a supported fold direction per structure.","Add unit tests covering every structure your generic fold code may receive."],"tags":["csharp","languageext","unsupported-operation","foldable"],"backgroundTag":"unsupported-operation","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}