How to get a range of details from a list starting with an index

I have a struct coming with a list of E-Card details from the database and I want to specify the starting index and the number of user details needed from the struct (limit). For following is a code

Ecards.where(batchId: params[“batchId”])
|> case do
cards ->

                    get = Enum.flat_map(get_details, fn string ->
                      for x <- convert_to_int(params["startIndex"])..(convert_to_int(params["startIndex"]) + convert_to_int(params["limit"])) do
                        Enum.fetch(list, x)

                      Status: 0, message: "Cards Listed from Index #{params["startIndex"]} to #{params["limit"]}",
                      cardList: get |> Poison.encode!(), totalCards: Enum.count(get)

Can you provide the current data set, and what you expect?

If I understood correctly, then Enum.slice/3 is your friend.

iex> list = [1,2,3,4,5,6]
iex> list |> Enum.slice(2, 2)
[3, 4]

Just checking: are these real PANs? :scream:

Moderator note: The post appeared to potentially contain PII so I’ve hidden it (and edited @al2o3cr’s message).

1 Like

No… Just demo pans

Thank you alot, it worked