witchcraft icon indicating copy to clipboard operation
witchcraft copied to clipboard

fmap alias <~ is not working

Open 21it opened this issue 4 years ago • 2 comments

fmap alias <~ is not working:

iex(1)> use Witchcraft                                                             
Witchcraft.Comonad                                                                 
iex(2)> &(&1+1) <~ [1, 2, 3]                                                       
#Function<7.126501267/1 in :erl_eval.expr/5>

21it avatar Mar 07 '20 14:03 21it

The following works, so perhaps it's only an issue with the shorthand form when using <~:

fn x -> x + 1 end <~ [1,2,3]

It's probably a separate issue, but I have had nested captures via & are not allowed errors whilst using Witchcraft when trying to chain (not nest) anonymous functions, which I've always resolved by using the fn ... end longhand form. Looking at the examples on various conference slides for the Witchcraft suite, I think this is a known issue and I assume it's to do with how it's shoehorned into Elixir.

asianfilm avatar Apr 10 '20 00:04 asianfilm

Actually additional brackets fix behaviour. But result of expression without brackets is completely unexpected. It should be compilation error in my opinion (if it can't be fixed).

iex(1)> use Witchcraft
Witchcraft.Comonad
iex(2)> &(&1+1) <~ [1, 2, 3]
#Function<7.126501267/1 in :erl_eval.expr/5>
iex(3)> (&(&1+1)) <~ [1, 2, 3]
[2, 3, 4]

21it avatar Apr 10 '20 07:04 21it