Skip to content

Commit 9ea48b3

Browse files
committed
release(4.1.0): deprecate procedural Try functions, keep Option
- Deprecate Result-based Try functions (Try_To_Result, Try_To_Functional_Result, Try_To_Any_Result_With_Param, Try_To_Result_With_Param) in favor of declarative Map_To_Result/Map_To_Result_With_Param - Keep Option-based Try functions (Try_To_Functional_Option, Try_To_Option_With_Param) - valid for "probe" operations with defaults - Reimplement To_Result/To_Option child packages with inline exception handling to eliminate internal deprecation warnings - Add "When to Use Option" documentation to functional-try.ads - Add GNATPP-TEMP to .gitignore - Add tools/puml/ for reference project tooling
1 parent 9db38a3 commit 9ea48b3

9 files changed

Lines changed: 75 additions & 44 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,6 @@ ENV/
277277
###############################################################################
278278
# Temporary
279279
###############################################################################
280+
281+
# GNAT Pretty Print temp files
282+
*__GNATPP-TEMP

CHANGELOG.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Changelog
22

3-
**Version:** 4.0.0
4-
**Date:** December 12, 2025
3+
**Version:** 4.1.0
4+
**Date:** December 18, 2025
55
**SPDX-License-Identifier:** BSD-3-Clause<br>
66
**License File:** See the LICENSE file in the project root.<br>
7-
**Copyright:** © 2025 Michael Gardner, A Bit of Help, Inc.<br>
8-
**Status:** Released
7+
**Copyright:** © 2025 Michael Gardner, A Bit of Help, Inc.<br>
8+
**Status:** Released
99

1010
All notable changes to this project will be documented in this file.
1111

@@ -14,9 +14,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
## [Unreleased]
1616

17+
---
18+
19+
## [4.1.0] - 2025-12-18
20+
1721
### Deprecated
1822

19-
#### Result-based Try functions
23+
#### Result-based Try functions (procedural Map_Exception pattern)
2024
- `Try_To_Result` - Use `Functional.Try.Map_To_Result`
2125
- `Try_To_Any_Result_With_Param` - Use `Functional.Try.Map_To_Result_With_Param`
2226
- `Try_To_Functional_Result` - Use `Functional.Try.Map_To_Result`
@@ -27,13 +31,18 @@ maintainable than procedural `Map_Exception` functions (code). The Map
2731
versions use a mapping array that is self-documenting and allows multiple
2832
exception-to-error-kind discriminations without if/elsif chains.
2933

30-
#### Option-based Try functions
31-
- `Try_To_Functional_Option` - Use `Functional.Try.Map_To_Result` with default
32-
- `Try_To_Option_With_Param` - Use `Functional.Try.Map_To_Result_With_Param` with default
34+
**Note:** Option-based Try functions (`Try_To_Functional_Option`,
35+
`Try_To_Option_With_Param`) are NOT deprecated. They serve valid use cases
36+
for "probe" operations with sensible defaults where error details don't matter.
37+
38+
### Changed
3339

34-
**Rationale:** Discarding exception context loses debuggability. Prefer
35-
Result with explicit `Unwrap_Or` at call site to preserve error information
36-
while still providing default fallback behavior.
40+
- `Functional.Try.To_Result` - Reimplemented with inline exception handling
41+
instead of delegating to deprecated `Try_To_Functional_Result`. This eliminates
42+
deprecation warnings when building the functional library itself.
43+
- `Functional.Try.To_Option` - Reimplemented with inline exception handling
44+
instead of delegating to `Try_To_Functional_Option` (consistency).
45+
- Added "When to Use Option" documentation section to `functional-try.ads`
3746

3847
---
3948

alire.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "functional"
22
description = "Functional Programming Library for Ada 2022"
3-
version = "4.0.0"
3+
version = "4.1.0"
44

55
authors = ["A Bit of Help, Inc. - Michael Gardner"]
66
maintainers = ["A Bit of Help, Inc. - Michael Gardner <mjgardner@abitofhelp.com>"]

src/functional-try-to_option.adb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ pragma Ada_2022;
88

99
package body Functional.Try.To_Option is
1010

11+
---------
12+
-- Run --
13+
---------
14+
1115
function Run return T_Option.Option is
12-
-- Instantiate the core generic function
13-
function Try_Impl is new
14-
Try_To_Functional_Option
15-
(T => T,
16-
Option_Pkg => T_Option,
17-
Action => Action);
1816
begin
19-
return Try_Impl;
17+
return T_Option.New_Some (Action);
18+
exception
19+
when others =>
20+
return T_Option.None;
2021
end Run;
2122

2223
end Functional.Try.To_Option;

src/functional-try-to_option.ads

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
pragma Ada_2022;
22
-- ===========================================================================
3-
-- Functional.Try.To_Option - Child package for backwards compatibility
3+
-- Functional.Try.To_Option - Simple Exception-to-Option Bridge
44
-- ===========================================================================
55
-- Copyright (c) 2025 Michael Gardner, A Bit of Help, Inc.
66
-- SPDX-License-Identifier: BSD-3-Clause
77
--
88
-- Purpose:
9-
-- Provides backwards-compatible API for existing tests.
10-
-- Wraps the generic function Functional.Try.Try_To_Functional_Option.
9+
-- Bridges exception-based code to Option types. Returns Some(value) on
10+
-- success, None on any exception.
1111
--
12-
-- Note:
13-
-- New code should use Functional.Try.Try_To_Functional_Option directly
14-
-- for cleaner syntax. This child package exists for test compatibility.
12+
-- When to Use:
13+
-- - "Probe" operations where you have a sensible default (Is_TZif_File, etc.)
14+
-- - "Best effort" reads with Unwrap_Or fallback (Read_Version, etc.)
15+
-- - Recursive traversals that skip on access errors (Count_Files, etc.)
16+
-- - When failure is expected/normal, not an error condition
17+
--
18+
-- When NOT to Use:
19+
-- - When error details matter for logging/debugging
20+
-- - When different exceptions need different handling
21+
-- - For critical operations where failures should be explicit
1522
--
1623
-- ===========================================================================
1724

src/functional-try-to_result.adb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ pragma Ada_2022;
88

99
package body Functional.Try.To_Result is
1010

11+
---------
12+
-- Run --
13+
---------
14+
1115
function Run return T_Result.Result is
12-
-- Instantiate the core generic function
13-
function Try_Impl is new
14-
Try_To_Functional_Result
15-
(T => T,
16-
E => E,
17-
Result_Pkg => T_Result,
18-
Map_Exception => Map_Exception,
19-
Action => Action);
2016
begin
21-
return Try_Impl;
17+
return T_Result.Ok (Action);
18+
exception
19+
when Occ : others =>
20+
return T_Result.New_Error (Map_Exception (Occ));
2221
end Run;
2322

2423
end Functional.Try.To_Result;

src/functional-try-to_result.ads

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
pragma Ada_2022;
22
-- ===========================================================================
3-
-- Functional.Try.To_Result - Child package for backwards compatibility
3+
-- Functional.Try.To_Result - Simple Exception-to-Result Bridge
44
-- ===========================================================================
55
-- Copyright (c) 2025 Michael Gardner, A Bit of Help, Inc.
66
-- SPDX-License-Identifier: BSD-3-Clause
77
--
88
-- Purpose:
9-
-- Provides backwards-compatible API for existing tests.
10-
-- Wraps the generic function Functional.Try.Try_To_Result.
9+
-- Bridges exception-based code to Result types using a procedural
10+
-- Map_Exception function for exception-to-error conversion.
1111
--
12-
-- Note:
13-
-- New code should use Functional.Try.Try_To_Functional_Result directly
14-
-- for cleaner syntax. This child package exists for test compatibility.
12+
-- When to Use:
13+
-- - Simple 1:1 exception-to-error mapping with procedural logic
14+
-- - When you need to inspect Exception_Occurrence for custom error building
15+
-- - Legacy code integration
16+
--
17+
-- When to Use Map_To_Result Instead:
18+
-- - Declarative exception mappings (data, not code)
19+
-- - Multiple exception types mapping to different error kinds
20+
-- - Self-documenting mapping tables
1521
--
1622
-- ===========================================================================
1723

src/functional-try.ads

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ pragma Ada_2022;
2929
-- - File paths, user IDs, configuration, etc.
3030
-- - Supports indefinite types like String
3131
--
32+
-- When to Use Option (Try_To_Functional_Option / Try_To_Option_With_Param):
33+
-- When you don't need error details and have a sensible default
34+
-- - "Probe" operations: Is_TZif_File, File_Exists, etc.
35+
-- - "Best effort" reads: Read_Version with Unwrap_Or("unknown")
36+
-- - Recursive traversals: Count_Files with Unwrap_Or(0) on access errors
37+
-- - Pattern: Try action, on ANY exception return None, then Unwrap_Or(default)
38+
-- - Appropriate when failure is expected/normal, not an error condition
39+
--
3240
-- Functions:
3341
-- Try_To_Result - No-param bridge to any Result type
3442
-- Try_To_Any_Result_With_Param - Parameterized bridge to any Result type
@@ -127,8 +135,7 @@ is
127135
type T is private;
128136
with package Option_Pkg is new Functional.Option (T => T);
129137
with function Action return T;
130-
function Try_To_Functional_Option return Option_Pkg.Option
131-
with Obsolescent => "Use Functional.Try.Map_To_Result with default";
138+
function Try_To_Functional_Option return Option_Pkg.Option;
132139

133140
-- ========================================================================
134141
-- Try_To_Result_With_Param - Parameterized Result bridge
@@ -161,7 +168,6 @@ is
161168
type Param (<>) is private;
162169
with package Option_Pkg is new Functional.Option (T => T);
163170
with function Action (P : Param) return T;
164-
function Try_To_Option_With_Param (P : Param) return Option_Pkg.Option
165-
with Obsolescent => "Use Functional.Try.Map_To_Result_With_Param with default";
171+
function Try_To_Option_With_Param (P : Param) return Option_Pkg.Option;
166172

167173
end Functional.Try;

tools/puml/plantuml.jar

24.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)