Maintaining type through a transformation #2315
RickBradford
started this conversation in
General
Replies: 1 comment 3 replies
-
Without knowing the surrounding code, my best guess is that |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Please excuse a basic question from a functional-first programmer, but I am trying to work out how to maintain the type (or class) of a list after I transform it.
So, I have a class called Story, and I create several instances of that in a list.
(setv storys (readwords "stories.txt"))
I now update that list using a 'map' function and place it in a new variable.
(setv updatedstorys (list (map(fn [s] (updater.update s)) storys)))
If I check the variable 'updatedstorys', the list has the correct number of elements, but the compiler does not recognize that the list contains Story elements, and produces an error.
(lfor s updatedstorys (print (s.name + " " + endtime.strftime ("%d-%B" ) + " - " + s.perc) ))
AttributeError: 'NoneType' object has no attribute 'name'
Any pointers on how to do this correctly would be much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions