Softanza
StartFrançais
Softanza
Research · narration

Taming Deep Lists with Softanza

Softanza, Mastering Depths from the Heart.

by Mansour Ayouni · in the repository since 2025-03-20 · feature essay · area Collections & objects

Softanza, Mastering the Depths
Softanza, Mastering the Depths

Softanza, Mastering the Depths

Deeply nested lists are powerful data structures but can become unwieldy as complexity grows. Softanza, an extension library for the Haro programming language, offers elegant solutions for managing these hierarchical structures. This article walks through practical approaches to common challenges with deep (nested) lists, introducing Softanza's features as they become relevant to solving real problems.

Finding Items Anywhere in Your Structure

One common challenge is finding all occurrences of a specific value within a deep list. With Softanza, this is straightforward:

Haro
o1 = new stzList([
    "A",
    [ "♥", "B", [ "C", "♥", "D", "♥" ], "♥", "E", "♥" ],
    "E"
])

? @@NL( o1.DeepFind("♥") )
#--> [
#    [ 2, 1 ],
#    [ 2, 3, 2 ],
#    [ 2, 3, 4 ],
#    [ 2, 4 ],
#    [ 2, 6 ]
#]

run on 2026-10-08 20:41 at commit 4a184e6f0: kept its promise

The DeepFind() method traverses the entire structure and returns a list of paths where the item exists. Each path is a list of indices that pinpoints the exact location of the item.

Making Global Changes

Once you've found items, you'll often want to replace them. Softanza makes this simple too:

Haro
o1.DeepReplace("♥", :By = "*")
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "*", "B", [ "C", "*", "D", "*" ], "*", "E", "*" ],
#    "E"
#]

run on 2026-10-08 20:41 at commit 4a184e6f0: kept its promise

Need to remove items instead? Just as easy:

Haro
o1.DeepRemove("*")
? @@NL( o1.Content() )
#--> [ "A", [ "B", [ "C", "D" ], "E" ], "E" ]

run on 2026-10-08 20:41 at commit 4a184e6f0: kept its promise

These methods operate throughout the entire data structure, making sweeping changes with minimal code.

Working with Specific Paths

But what if you need more precision? What if you want to operate on just part of your data structure? This is where paths come in.

A path in Softanza is simply a list of indices that locates an item. For example, in our list, the path [2, 3, 2] refers to the second item within the third item within the second item of the main list.

Softanza can show you all possible paths in your structure:

Haro
o1 = new stzList([
    "item1",
    [ "item21", [ "item221", "item222" ], "item23" ],
    [ "item31", [ "item321" ] ],
    "item4"
])

? @@NL( o1.Paths() )
#--> [
#    [ 1 ],
#    [ 2 ],
#    [ 2, 1 ],
#    [ 2, 2 ],
#    [ 2, 2, 1 ],
#    [ 2, 2, 2 ],
#    [ 2, 3 ],
#    [ 3 ],
#    [ 3, 1 ],
#    [ 3, 2 ],
#    [ 3, 2, 1 ],
#    [ 4 ]
#]

run on 2026-10-08 20:41 at commit 4a184e6f0: kept its promise

With paths, you can access specific items directly:

Haro
? o1.ItemAtPath([2, 2, 2])
#--> "item222"

? @@( o1.ItemsAtPaths([ [2, 2, 2], [3, 1], [4] ]) )
#--> [ "item222", "item31", "item4" ]

illustration

Targeting Specific Locations

When you need to focus on particular parts of your data structure, Softanza offers two key approaches: finding at endpoints or along paths.

Haro
o1 = new stzList([
    "A",
    [ "♥", "B", [ "C", "♥", "D", "♥" ], "♥", "E", "♥" ],
    "E"
])

illustration

To check if a specific item exists at a particular endpoint:

Haro
? @@( o1.DeepFindAt("♥", [2, 3, 2]) )
#--> [2, 3, 2]  # Returns the path if found

illustration

To find occurrences along a path (from root to endpoint):

Haro
? @@( o1.DeepFindIn("♥", [2, 3, 2]) )
#--> [ [2, 1], [2, 3, 2] ]  # Returns all paths where "♥" is found

illustration

Similarly, you can make targeted changes:

Haro
# Replace only at the endpoint
o1.DeepReplaceAt("★", [2, 3, 2])
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "♥", "B", [ "C", "★", "D", "♥" ], "♥", "E", "♥" ],
#    "E"
#]

illustration

Operations on Specific Items

As your needs grow more sophisticated, you may want to apply changes only to specific items. Softanza uses the "This" indicator for such operations:

Haro
# Replace only if the item at the path equals "♥"
o1.DeepReplaceThisAt("♥", "★", [2, 4])
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "♥", "B", [ "C", "★", "D", "♥" ], "★", "E", "♥" ],
#    "E"
#]

# No change if the item doesn't match
o1.DeepReplaceThisAt("C", "★", [2, 4])  # No effect since "★" is at [2, 4], not "C"

illustration

The same principle applies to operations along paths:

Haro
# Replace all "♥" symbols along path [2, 3] with "★"
o1.DeepReplaceThisIn("♥", "★", [2, 3])
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "♥", "B", [ "C", "★", "D", "★" ], "★", "E", "♥" ],
#    "E"
#]

illustration

Working with Multiple Paths

When you need to perform the same operation across different locations, the "Many" suffix comes in handy:

Haro
# Replace at multiple specific endpoints
o1.DeepReplaceAtMany("◆", [ [2, 1], [2, 6] ])
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "◆", "B", [ "C", "★", "D", "★" ], "★", "E", "◆" ],
#    "E"
#]

illustration

Multiple Item Operations

For more complex transformations involving multiple items, Softanza offers "These" and "Many" variants:

Haro
# Replace both "★" and "D" with "△" along path [2, 3]
o1.DeepReplaceTheseIn(["★", "D"], "△", [2, 3])
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "◆", "B", [ "C", "△", "△", "△" ], "★", "E", "◆" ],
#    "E"
#]

illustration

You can even replace different items with different values:

Haro
# Replace "△" with "○" and "C" with "□" along path [2, 3]
o1.DeepReplaceManyByManyIn(["△", "C"], ["○", "□"], [2, 3])
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "◆", "B", [ "□", "○", "○", "○" ], "★", "E", "◆" ],
#    "E"
#]

illustration

Extended Processing

When dealing with uneven replacement lists, the "XT" suffix enables cycling through replacement values:

Haro
# Replace "○", "□" and "★" with cycling through "■" and "▲"
o1.DeepReplaceManyByManyInXT(["○", "□", "★"], ["■", "▲"], [2, 3])
? @@NL( o1.Content() )
#--> [
#    "A",
#    [ "◆", "B", [ "▲", "■", "■", "▲" ], "■", "E", "◆" ],
#    "E"
#]

illustration

Advanced Path Operations

As you become more familiar with paths, Softanza offers tools to help you manage them:

Finding Special Paths

Haro
# Find the longest paths
? @@( o1.LongestPaths() )
#--> [ [ 2, 3, 1 ], [ 2, 3, 2 ], [ 2, 3, 3 ], [ 2, 3, 4 ] ]

# Find paths at a specific depth
? @@( o1.PathsAtDepth(2) )
#--> [ [ 2, 1 ], [ 2, 2 ], [ 2, 3 ], [ 3, 1 ], [ 3, 2 ] ]

illustration

Understanding Path Relationships

Haro
# Check if one path is a subpath of another
? IsSubPathOf([2], [2, 3, 4])
#--> TRUE

# Find the common ancestor of multiple paths
? @@( CommonPath([ [2, 1, 3], [2, 1, 4], [2, 1, 5] ]) )
#--> [2, 1]

run on 2026-10-08 20:41 at commit 4a184e6f0: kept its promise

Expanding and Focusing

Haro
# Expand a path to include all its subpaths
? @@NL( o1.ExpandPath([2, 3]) )
#--> [
#    [ 2, 3 ],
#    [ 2, 3, 1 ],
#    [ 2, 3, 2 ],
#    [ 2, 3, 3 ],
#    [ 2, 3, 4 ]
#]

# Collapse a path to its parent
? @@( o1.CollapsePath([2, 3, 4]) )
#--> [2]

illustration

Beyond Simple Values

Softanza's tools extend beyond simple replacements. You can apply transformations too:

Haro
o1 = new stzList([
    "you",
    "other",
    [ "other", "you", [ "you" ], "other" ],
    "you"
])

# Uppercase all occurrences of "other"
o1.DeepUppercaseString("other")
? @@NL( o1.Content() )
#--> [
#    "you",
#    "OTHER",
#    [ "OTHER", "you", [ "you" ], "OTHER" ],
#    "you"
#]

illustration

Real-World Applications

These features combine powerfully in practical scenarios:

  • Configuration Management: Find all settings with DeepFind(), then modify specific ones with DeepReplaceThisAt().
  • Data Transformation: Convert JSON-like structures by replacing values at different depths.
  • Content Processing: Search for patterns with DeepFindIn() and transform them contextually.
  • Data Cleaning: Remove unwanted items from specific sections using DeepRemoveThisIn().

The Softanza Advantage

In this section, we compare Softanza to several mainstream languages in the field of deep list and path management.

Legend: - ✅ Full native support - ⚙️ Possible with custom implementation - 🔄 Partial support

Deep List Feature Softanza (Haro) Wolfram Language Python (jsonpath-ng) JavaScript (Lodash) C# (LINQ/JSON.NET) Java (Stream API/Jackson)
Deep Finding (DeepFind()) ✅ ✅ 🔄 ⚙️ 🔄 🔄
Global Replacement (DeepReplace(:By)) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Deep Removal (DeepRemove()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Path Enumeration (Paths()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Path-Specific Access (ItemAtPath()) ✅ ✅ 🔄 ✅ 🔄 🔄
Multiple Path Operations (ItemsAtPaths()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Targeted Replacement (DeepReplaceAt()) ✅ ✅ ⚙️ ✅ ⚙️ ⚙️
Path Traversal Operations (DeepFindIn()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Value-Specific Operations (DeepReplaceThisAt()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Multi-Target Operations (DeepReplaceTheseIn()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Complex Value Mapping (DeepReplaceManyByManyIn()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️
Cycling Replacements (DeepReplaceManyByManyInXT()) ✅ 🔄 ⚙️ ⚙️ ⚙️ ⚙️
Path Analysis (LongestPaths(), PathsAtDepth()) ✅ 🔄 ⚙️ ⚙️ ⚙️ ⚙️
Path Relationships (IsSubPathOf(), CommonPath()) ✅ 🔄 ⚙️ ⚙️ ⚙️ ⚙️
Path Expansion (ExpandPath(), CollapsePath()) ✅ ⚙️ ⚙️ ⚙️ ⚙️ ⚙️
Deep String Transformations (DeepUppercaseString()) ✅ ✅ ⚙️ ⚙️ ⚙️ ⚙️

Key Takeaways: 1. Softanza remains the only solution with full native support for all operations. 2. Wolfram Language is the closest alternative, though it follows a different programming paradigm. 3. Python, JavaScript, C#, and Java require custom implementations for most complex nested operations. 4. C#'s LINQ and Java's Stream API are powerful but not designed for deep list and path manipulation. 5. Most mainstream languages follow this pattern: - Basic path access is available (partially or via libraries). - Deep finding operations have partial or custom support. - Complex operations like targeted replacements, path analysis, and relationship checking require custom implementation.

Conclusion

Softanza transforms complex operations on deep lists from tedious tasks into elegant one-liners. By providing intuitive methods that build on familiar concepts, it lets you focus on what you want to accomplish rather than how to navigate complex structures.

The library's consistent naming patterns make your code more readable and maintainable. As your needs grow from simple searches to complex replacements across multiple paths, Softanza offers just the right tool for each challenge.

Cite

Mansour Ayouni. "Taming Deep Lists with Softanza". Softanza narrations, 2025. https://mayouni.github.io/stzsite/en/narrations/stz-managing-deep-lists-narration.html

Run in Haro's name on 2026-10-08 20:41 inside the library at commit 4a184e6f0, block after block in one process: 5 of 19 blocks kept their promise; the others are illustrations. The code of the articles is Haro code. Where an article was written before the language took its present name, the name was changed and nothing else. Genre, area and series read from the file's name, the year from its first commit: derived, until the article carries its own header. The file on GitHub(opens in a new tab)