My async call is returning before list is populated in forEach loop

This code Future<List<String>> readHeaderData() async { List<String> l = new List(); List<String> files = await readHeaders(); // Gets filenames files.forEach((filename) async { final file = await File(filename); String contents = await file.readAsString(); User user = User.fromJson(json.decode(contents)); String name = user.NameLast + “, ” + user.NameFirst; print(name); l.add(name); } return l; } returns the list l … Read more

List.shuffle() in Dart?

There is a shuffle method in the List class. The methods shuffles the list in place. You can call it without an argument or provide a random number generator instance: var list = [‘a’, ‘b’, ‘c’, ‘d’]; list.shuffle(); print(‘$list’); The collection package comes with a shuffle function/extension that also supports specifying a sub range to … Read more

How to count number of element occurrences in a list in Prolog

The following is based on my previous answer to “Remove duplicates in list (Prolog)” and on this previous answer to the question “Prolog union for A U B U C”. list_item_subtracted_count0_count/5 is derived from list_item_subtracted/3. list_counts/2 is derived from list_setB/2, which were both defined here. list_item_subtracted_count0_count([], _, [], N,N). list_item_subtracted_count0_count([A|As], E, Bs1, N0,N) :- if_(A … Read more

Prolog: First duplicate value

Here is a pure version using dif/2 which implements sound inequality. dif/2 is offered by B-Prolog, YAP-Prolog, SICStus-Prolog and SWI-Prolog. firstdup(E, [E|L]) :- member(E, L). firstdup(E, [N|L]) :- non_member(N, L), firstdup(E, L). member(E, [E|_L]). member(E, [_X|L]) :- member(E, L). non_member(_E, []). non_member(E, [F|Fs]) :- dif(E, F), non_member(E, Fs). The advantages are that it can also … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)