Skip to content

How to append to List? #470

Closed Answered by jtdaugherty
refaelsh asked this question in Q&A
Jun 6, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

The function to modify the list would be something like \lst -> listReplace (listElements lst <> elementsToAppend) (Just i) lst where i is the index of the element that you want selected after the modification. In the context of EventM, you'd either use this with a lens (i.e. assuming appStateList is a lens made from the _appStateLens field of your application state type) like

lst <- use appStateList
let newElements = listElements lst <> elementsToAppend
appStateList %= listReplace newElements (Just i)

or without a lens (i.e. assuming appStateList is just a record field of your application state type) like

lst <- gets appStateList
let newElements = listElements lst <> elementsToAppend
mod…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@jtdaugherty
Comment options

Answer selected by refaelsh
@refaelsh
Comment options

@jtdaugherty
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants