Deduct "New List" with "new Value" only for some "specific Tag", from Old List, using "List Comprehension".
Papa Tana
papa.tana101@REDACTED
Sun Jul 19 09:59:31 CEST 2020
Hi,
Thanks for your answer.
> Sorry, I didn't see you required list comprehension. Don't know why you have
> this requirement, though - many other ways to do it.
This T list is just a dummy example.
I have this requirement because in real life, I have 125 types of list
"REQ" compound of {Tag, Value}.
I need to process some tags inside them, transform, and answer back
with a response "RESP".
create_response(<<1, REQ/binary>>) ->
Length = [ integer_to_list(V,16) || {T,V} <- REQ , T == length ],
Charging_Characteristics = [ V || {T,V} <- REQ , T ==
charging_characteristics ],
Protocols_Configurations_Payload = [ V || {T,V} <- REQ , T ==
protocols_configurations ],
QoS_Payload = [ V || {T,V} <- REQ , T == qos ],....
.......
create_response(<<125, REQ/binary>>) ->
SelectionMode = [ V || {T,V} <- REQ , T == selection_mode ],
TearDownIndication = [ V || {T,V} <- REQ , T == teardown_indication ],
User_Location_Information_Payload = [ V || {T,V} <- REQ , T ==
user_location_information ],..........
So, I have to change;
- new Length depending on Old Length input,
- new Charging_Characteristics depending on Input of Charging_Characteristics,
- new Protocols_Configurations_Payload depending on Old
Protocols_Configurations_Payload Input,
- QoS_Payload depending on QoS_Payload input,
- etc...
After trying to create a lot of anonymous function to process each
desired Tag inside 125 different type of request, I was thinking that
List comprehension using some filter would be succinct and easy to
maintain.
Best Regards,
More information about the erlang-questions
mailing list