Packages

A CNAB file helper. This library aims to help your bank or cooperative read, decode, display, and perform various operations on a CNAB file. Supported operations: - Read CNAB240 file - Return some data - Get details type

Current section

Files

Jump to
ex_cnab app excnab cnab240 services has_identical_informations.ex
Raw

app/excnab/cnab240/services/has_identical_informations.ex

defmodule ExCnab.Cnab240.Services.HasIdenticalInformations do
@moduledoc """
Service to check if the CNAB 240 file has identical informations.
"""
@spec run(list) :: :ok | {:error, String.t()}
def run(list), do: find_list(list, list, :ok)
defp find_list(list, [hd | tl], :ok) do
index = Enum.find_index(tl, &(&1 == hd))
currentIndex = Enum.find_index(list, &(&1 == hd))
case index do
nil ->
find_list(list, tl, :ok)
_ ->
{:error, "A linha #{currentIndex + 1} está duplicada"}
end
end
defp find_list(_list, [], :ok), do: :ok
end