@@ -74,45 +74,37 @@ object ConfigurationManagement {
7474 }
7575
7676 // Basic decoders
77- implicit val stringDecoder : ConfigDecoder [String ] = new ConfigDecoder [String ] {
78- def decode (config : Config , path : String ): ValidatedNel [ConfigError , String ] =
79- Safety
80- .safely(config.getString(path))(ErrorMapper .default)
81- .leftMap(_ => ConfigError .MissingKey (path))
82- .toValidatedNel
83- }
84-
85- implicit val intDecoder : ConfigDecoder [Int ] = new ConfigDecoder [Int ] {
86- def decode (config : Config , path : String ): ValidatedNel [ConfigError , Int ] =
87- Safety
88- .safely(config.getInt(path))(ErrorMapper .default)
89- .leftMap(_ => ConfigError .MissingKey (path))
90- .toValidatedNel
91- }
92-
93- implicit val booleanDecoder : ConfigDecoder [Boolean ] = new ConfigDecoder [Boolean ] {
94- def decode (config : Config , path : String ): ValidatedNel [ConfigError , Boolean ] =
95- Safety
96- .safely(config.getBoolean(path))(ErrorMapper .default)
97- .leftMap(_ => ConfigError .MissingKey (path))
98- .toValidatedNel
99- }
77+ implicit val stringDecoder : ConfigDecoder [String ] = (config : Config , path : String ) =>
78+ Safety
79+ .safely(config.getString(path))(ErrorMapper .default)
80+ .leftMap(_ => ConfigError .MissingKey (path))
81+ .toValidatedNel
82+
83+ implicit val intDecoder : ConfigDecoder [Int ] = (config : Config , path : String ) =>
84+ Safety
85+ .safely(config.getInt(path))(ErrorMapper .default)
86+ .leftMap(_ => ConfigError .MissingKey (path))
87+ .toValidatedNel
88+
89+ implicit val booleanDecoder : ConfigDecoder [Boolean ] = (config : Config , path : String ) =>
90+ Safety
91+ .safely(config.getBoolean(path))(ErrorMapper .default)
92+ .leftMap(_ => ConfigError .MissingKey (path))
93+ .toValidatedNel
10094
10195 // Temporary simple FlowForgeConfig decoder - TODO: implement proper decoding
10296 implicit val flowForgeConfigDecoder : ConfigDecoder [FlowForgeConfig ] =
103- new ConfigDecoder [FlowForgeConfig ] {
104- def decode (cfg : Config , path : String ): ValidatedNel [ConfigError , FlowForgeConfig ] = {
105- // Flatten Typesafe config to a flat Map[String,String] (dot paths) and delegate to core decoder
106- import scala .jdk .CollectionConverters ._
107- val entries = cfg.entrySet().asScala.toList
108- val flat : Map [String , String ] = entries.flatMap { e =>
109- val key = e.getKey
110- Safety .safely(cfg.getString(key))(ErrorMapper .default).toOption.map(v => key -> v)
111- }.toMap
112- val coreDecoder = ConfigurationAlgebra .flowForgeConfigDecoder
113- coreDecoder
114- .decode(flat)
115- .leftMap(_.map(err => ConfigError .ParseError (path, err.toString)))
116- }
97+ (cfg : Config , path : String ) => {
98+ // Flatten Typesafe config to a flat Map[String,String] (dot paths) and delegate to core decoder
99+ import scala .jdk .CollectionConverters ._
100+ val entries = cfg.entrySet().asScala.toList
101+ val flat : Map [String , String ] = entries.flatMap { e =>
102+ val key = e.getKey
103+ Safety .safely(cfg.getString(key))(ErrorMapper .default).toOption.map(v => key -> v)
104+ }.toMap
105+ val coreDecoder = ConfigurationAlgebra .flowForgeConfigDecoder
106+ coreDecoder
107+ .decode(flat)
108+ .leftMap(_.map(err => ConfigError .ParseError (path, err.toString)))
117109 }
118110}
0 commit comments