# 2n: functional hacks ### `++cork` Build `f` such that `(f x) .= (b (a x))`. `a` is a noun. `b` is a gate. Source ------ ++ cork |*({a/_|=(* **) b/gate} (corl b a)) :: compose forward Examples -------- > (:(cork dec dec dec) 20) 17 > =mal (mo (limo a+15 b+23 ~)) > ((cork ~(got by mal) dec) %a) 14 > ((cork ~(got by mal) dec) %b) 22 *** ### `++corl` Gate compose XX Revisit `a` is a gate. `b` is a noun. Source ------ ++ corl :: compose backwards |* {a/gate b/_|=(* **)} =< +:|.((a (b))) :: span check |* c/_+<.b (a (b c)) :: Examples -------- > ((corl (lift bex) (slat %ud)) '2') [~ 4] *** ### `++curr` Right curry Right curry a gate, binding the tail of its sample Accepts ------- `a` is a gate. `c` is a noun. Produces -------- Source ------ ++ curr :: curry right |* {a/_|=(^ **) c/*} |* b/_+<+.a (a b c) :: Examples -------- > =tep (curr scan sym) > `@t`(tep "asd") 'asd' > `@t`(tep "lek-om") 'lek-om' *** ### `++cury` Curry a gate, binding the head of its sample Accepts ------- `a` is a gate. `b` is a noun. Produces -------- A gate. Source ------ ++ cury :: curry left |* {a/_|=(^ **) b/*} |* c/_+<+.a (a b c) :: Examples -------- > =mol (cury add 2) > (mol 4) 6 > (mol 7) 9 *** ### `++hard` Demands that a specific type be produced, crashing the program is it is not. Source ------ ++ cury :: curry left |* {a/_|=(^ **) b/*} |* c/_+<+.a (a b c) :: Examples -------- > ((hard (list)) (limo [1 2 3 ~])) ~[1 2 3] > ((hard @) (add 2 2)) 4 > ((hard @t) (crip "Tape to cord, bro!")) 'Tape to cord, bro' > ((hard tape) (crip "...Tape to cord, bro?...")) ! hard ! exit *** ### `++soft` Politely requests a specific type to be produced, producing null if it is not. Source ------ ++ soft :: maybe coerce to span |* han/$-(* *) |= fud/* ^- (unit han) =+ gol=(han fud) ?.(=(gol fud) ~ [~ gol]) :: Examples -------- > ((soft %4) (add 2 2)) [~ %4] > ((soft @) (add 2 2)) [~ 4] > ((soft %5) (add 2 2)) ~ > ((soft @t) (crip "Tape to cord, Woohoo!")) [~ 'Tape to cord, Woohoo!'] > ((soft @t) (trip 'Cmon man... Tape to cord? Please?!')) ~ ***