Mt940 parsed list

Hello,

I have parsed an MT940 file that returns the list of structs as shown below.
I dont need all the structs returned and certainly not the first struct.
1.How can i access these structs in the list returned without having to use the syntax
[variable = %name{} = _head | _rest ] = list just to get to those structs i want.
2. Please note,the structs %MT940.Statementline{} and %MT940.StatementlineInformation{} repeat as many times depending on the :61: tag occurrences in the original mt940 file.

[
  [
    %MT940.Job{
      content: "BAFZMSWI1434872",
      modifier: nil,
      reference: "BAFZMSWI1434872"
    },
    %MT940.Account{
      account_currency: nil,
      account_number: "ZMB0X1XXXXX",
      bank_code: nil,
      content: "ZMB0X1XXXXX",
      modifier: nil
    },
    %MT940.Statement{
      content: "00092/00006",
      modifier: "C",
      number: 92,
      sheet: 6
    },
    %MT940.AccountBalance{
      amount: #Decimal<27505.50>,
      balance_type: :intermediate,
      content: "C200515ZMW27505,50",
      currency: "ZMW",
      date: ~N[2020-05-15 00:00:00],
      modifier: "M",
      sign: :credit
    },
    %MT940.StatementLine{
      amount: #Decimal<500.10>,
      content: "2005150515C500,10NMSC000000014//0500650601140021004029630/CHD/",
      entry_date: ~N[2020-05-15 00:00:00],
      funds_code: :credit,
      modifier: nil,
      reference: "000000014",
      swift_code: "NMSC",
      transaction_description: "0500650601140021004029630/CHD/",
      value_date: ~N[2020-05-15 00:00:00]
    },
    %MT940.StatementLineInformation{
      account_holder: [],
      account_number: nil,
      bank_code: nil,
      code: nil,
      content: "CTPTY: REVENUE AUTHORITY REMIT:1004029630/CHD/2020/C/7833SERIAL:000000014",
      details: ["CTPTY:REVENUE AUTHORITY REMIT:1004029630/CHD/2020/C/7833SERIAL:000000014"],
      modifier: nil,
      not_implemented_fields: [],
      prima_nota: nil,
      text_key_extension: nil,
      transaction_description: nil
    },
    %MT940.StatementLine{
      amount: #Decimal<500.10>,
      content: "2005150515C500,10NMSC000000015//0500650601150021004029630/CHD/",
      entry_date: ~N[2020-05-15 00:00:00],
      funds_code: :credit,
      modifier: nil,
      reference: "000000015",
      swift_code: "NMSC",
      transaction_description: "0500650601150021004029630/CHD/",
      value_date: ~N[2020-05-15 00:00:00]
    },
    %MT940.StatementLineInformation{
      account_holder: [],
      account_number: nil,
      bank_code: nil,
      code: nil,
      content: "CTPTY: REVENUE AUTHORITY REMIT:1004029630/CHD/2020/C/7834SERIAL:000000015",
      details: ["CTPTY:REVENUE AUTHORITY REMIT:1004029630/CHD/2020/C/7834SERIAL:000000015"],
      modifier: nil,
      not_implemented_fields: [],
      prima_nota: nil,
      text_key_extension: nil,
      transaction_description: nil
    },
    %MT940.StatementLine{
      amount: #Decimal<500.10>,
      content: "2005150515C500,10NMSC000000016//0500650601160021001716173/KZU/",
      entry_date: ~N[2020-05-15 00:00:00],
      funds_code: :credit,
      modifier: nil,
      reference: "000000016",
      swift_code: "NMSC",
      transaction_description: "0500650601160021001716173/KZU/",
      value_date: ~N[2020-05-15 00:00:00]
    },
    %MT940.StatementLineInformation{
      account_holder: [],
      account_number: nil,
      bank_code: nil,
      code: nil,
      content: "CTPTY: REVENUE AUTHORITY REMIT:1001716173/KZU/2020/C/7926SERIAL:000000016",
      details: ["CTPTY:REVENUE AUTHORITY REMIT:1001716173/KZU/2020/C/7926SERIAL:000000016"],
      modifier: nil,
      not_implemented_fields: [],
      prima_nota: nil,
      text_key_extension: nil,
      transaction_description: nil
    },
    %MT940.StatementLine{
      amount: #Decimal<4000.80>,
      content: "2005150515D4000,80NTFR000000000//050065041377001 ASYCUDA TAX",
      entry_date: ~N[2020-05-15 00:00:00],
      funds_code: :debit,
      modifier: nil,
      reference: "000000000",
      swift_code: "NTFR",
      transaction_description: "050065041377001ASYCUDA TAX",
      value_date: ~N[2020-05-15 00:00:00]
    },
    %MT940.StatementLineInformation{
      account_holder: [],
      account_number: nil,
      bank_code: nil,
      code: nil,
      content: "CTPTY: REVENUE AUTHORITY REMIT:BAFZMSWI1434558SERIAL:000000000",
      details: ["CTPTY: REVENUE AUTHORITY REMIT:BAFZMSWI1434558SERIAL:000000000"],
      modifier: nil,
      not_implemented_fields: [],
      prima_nota: nil,
      text_key_extension: nil,
      transaction_description: nil
    },
    %MT940.ClosingBalance{
      amount: #Decimal<25005.00>,
      balance_type: :start,
      content: "C200515ZMW25005,00",
      currency: "ZMW",
      date: ~N[2020-05-15 00:00:00],
      modifier: "F",
      sign: :credit
    },
    %MT940.ValutaBalance{
      amount: #Decimal<25005.00>,
      balance_type: nil,
      content: "C200515ZMW25005,00",
      currency: "ZMW",
      date: ~N[2020-05-15 00:00:00],
      modifier: nil,
      sign: :credit
    },
    %MT940.FutureValutaBalance{
      amount: #Decimal<25005.00>,
      balance_type: nil,
      content: "C200518ZMW25005,00",
      currency: "ZMW",
      date: ~N[2020-05-18 00:00:00],
      modifier: nil,
      sign: :credit
    },
    %MT940.FutureValutaBalance{
      amount: #Decimal<25005.00>,
      balance_type: nil,
      content: "C200519ZMW25005,00",
      currency: "ZMW",
      date: ~N[2020-05-19 00:00:00],
      modifier: nil,
      sign: :credit
    }
  ]
]

Can you please use the triple backtick syntax (```) before and after your coding blocks? It’s hard reading it otherwise.

To access the first, use hd/1, to drop it use tl/1, to filter use Enum.filter/2.

Thanks for reformatting it. Now can you show us what have you tried so far, including with the info @NobbZ gave you?

While i wait to try out @NobbZ idea,
I havent yet found a way of accessing these structs but my function that receives the list looks like that

def generateZRA(list) do
    # tuple=list
    # |>List.to_tuple

    list

    # |> Enum.group_by(& &1.content, & %{"id" => &1.modifier})
    # |> Enum.chunk_every(2)
    # |> Map.new(fn [k, v] -> {k, v} end)

    # map
    # [account = %MT940.Job{} = _head | rest] = list
    # [job = %MT940.Job{content: c, modifier: m, reference: r}, h,f,g] = list
    # account
    # job
  end```

I am still not clear what exactly you want to do. If you want to group by content then indeed your code that does this – Enum.group_by(& &1.content, & %{"id" => &1.modifier}) – looks to be correct on a first glance. But from then on, I am not sure what you are aiming at. What’s your desired result?