How to pass closures to another function?

hi dear all, anyone know how to make this work?

dropUselessBy = fn( g, ga ) ->

	ga = ga -- [ g ]
	ga ++ [ Map.drop( g, [ :stid, :oa, :og, :runtime ] ) ]
end

ga = Enum.reduce( ga, [], dropUseLessBy/2 ) #this is wrong

thanks

You properly meant Enum.reduce(ga, [], &dropUseLessBy/2) or Enum.reduce(ga, [], fn g, acc -> dropUseLessBy.(g, acc))

He meant Enum.reduce( ga, [], dropUseLessBy ).

3 Likes

i tryed Enum.reduce( ga, [], dropUseLessBy )
but always get undefined function dropUseLessBy/0 :disappointed_relieved:

Yes, thats because dropUseLessBy is not the same as dropUselessBy, its a simple typo.

If everything is spelled the same it works:

iex(1)> f = fn x, y -> x + y end
#Function<12.127694169/2 in :erl_eval.expr/5>
iex(2)> Enum.reduce(1..10, 0, f)
55
2 Likes

Geeee… that’s typo… it’s my fault :sweat_smile:

thank you guys :smile::smile::smile::smile::smile:

2 Likes