erlang - Design pattern? Function iterating through a list in search of the first {success} result -


I have a coding problem in Erlang which is probably a normal design pattern, but I can not find any information about it. I

How to solve it

I've got the L list. I want to apply the function to each element in L, and it is run concurrently in all the elements of L. Each call for the Element will either succeed or fail; In most cases it will fail, but sometimes it will be successful for a specific element within L.

If / when Air Force (Elements) succeeds, then I will eliminate all the inventions of F for other elements of "success" and L - the first "success" I am interested in all. On the other hand, if L (Elment) fails for every element in L, then I want to "return".

As a trivial example, suppose a list of L integers And F returns {success} If there is an element 3 in L, or for any other value {fail} I want to meet as soon as possible if there is any 3s in L; I do not care that at least The less one can exist in existence or not. F can look like this:

  f (int) -> case int 3 -> {success}; _ - & gt; {failed} end  

one of the inputs How can I find out through the list that there is at least one in the list 3, and return as soon as possible?

Definitely this is a normal functional design pattern, and I just google I'm not using the right search terms within ...

  Any (F, List) - As already mentioned in your solution Level has been, lists to use: None / 2.  

It's not like the Concurrent Versions: & gt; Parent = self (), PED = Eggs (Interesting) - & gt; Get spammer (parent, f, list) end) (PID, result) - & gt; The end result, the result spornor (parent, f, list) - & gt; Spawner = self (), S = spawn_link (funny) - & gt; Wait_fire_selt (spammer, parent, length (list)) end, [spawn_link (funny) - & gt; Run (s, f) end) || X & lt; - list], receive after infinity - & gt; OK End wait_for_result (Spøner, Parents, 0) - & gt; mother-father! {Sporer, false}, exit (is_stress); Wait_for_result (spawar, parent, child) - & gt; Get the truth - & gt; mother-father! {Spouters, true}, exit (is_stress); False - & gt; Wait_for_result (spawn, parent, child-1) end Run (s, f) - & gt; Hold the key of truth (F ()) - & gt; s! truth; _ - & gt; s! Wrong end

Note that the "wait_for_children" process is an exit (I_result) when all children ("run" process) will die.

Completely unhealthy ... Ah, what would I do as an example:

  4> Game: Any (funny (A) -> A == end, [B, B, B, B, B, B, B, B]). False 5 & gt; Play: Any (funny (A) -> A == end, [B, B, B, B, B, B, A, B]) 


Comments