is this a spot for functional lenses in javascript? -


playing around point-free style javascript fun.

say coding video game diablo, , modeling enemies using complex nested types deeper , more complicated:

{ name: "badguy1", stats: { health: 10: strength: 42 }, pos: {x: 100, y: 101 } } 

so have list of enemies. want damage enemies within radius

function isinrange(radius, point) { return point.x^2 + point.y^2 >= radius^2; } function firedamage(health) { return health - 10; }     var newenemies = enemies.filter(isinrange).map(firedamage); 

this of course doesn't type check - combinators take primitives, need map , filter "down level". don't want obscure filter/map business logic pipeline. i know lenses can me lets in browser, of course trivial mutable structures. how do it?

read my article on lenses. answers question way worded it. seriously, i'm not joking. here's code snippet post:

firebreath :: point -> statet game io () firebreath target =     lift $ putstrln "*rawr*"     units.traversed.(around target 1.0).health -= 3 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -