Your SlideShare is downloading. ×
0
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
2013 28-03-dak-why-fp
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

2013 28-03-dak-why-fp

97

Published on

My speech on Why functional programming.

My speech on Why functional programming.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
97
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Почему функциональноепрограммирование? Сборная солянка
  • 2. def sum(list): result = 0 for element in list: result = result + element return resultsum [] = 0sum (x:xs) = x + sum xs
  • 3. public static <E extends Comparable<? super E>> List<E> quickSort(List<E> arr) { if (arr.size() <= 1) return arr; E pivot = arr.getFirst(); List<E> less = new LinkedList<E>(); List<E> pivotList = new LinkedList<E>(); List<E> more = new LinkedList<E>(); for (E i: arr) { if (i.compareTo(pivot) < 0) less.add(i); else if (i.compareTo(pivot) > 0) more.add(i); else pivotList.add(i); } less = quickSort(less); more = quickSort(more); less.addAll(pivotList); less.addAll(more); return less;}
  • 4. def qsort[T <% Ordered[T]](list:List[T]):List[T] = { list match { case Nil => Nil case x::xs => val (before,after) = xs partition (_ < x) qsort(before) ++ (x :: qsort(after)) }}
  • 5. sum(L) -> lists:foldl(fun(X, Sum) -> X + Sum end, 0, L).
  • 6. ПараллелизмПрограмма выполняетсябыстрее в условияхмногоядерного окруженияКонкурентностьНеизбежноевзаимодействиеконкурентных потоков впредметной области
  • 7. var x = 0;setTimeout(function () { x = x + 1; }, 0);setTimeout(function () { x = x * 2; }, 0);console.log(x);
  • 8. $people = array();$men = array();$women = array();foreach ($people as $person) { array_push(($person->gender == male ? $men : $women), $person)}val people: Array[Person]val (men, women) = people partition (_.gender == "male")
  • 9. ???val people: Array[Person]val (men, women) = people.par partition (_.gender == "male")
  • 10. ???val people: Array[Person]val totalMoney = people.par map (_.money) reduce (_+_)
  • 11. actor { receive { case people: Set[Person] => val (men, women) = people partition (_.gender == "male") Cosmopolitan ! women Playboy ! men }}
  • 12. class OrderController < ApplicationController before_filter :authenticate_user! before_filter :load_order, only: [:edit, :update, :destroy] before_filter :create_order_from_params, only: [:new, :create] before_filter :authorize_user_on_order!, only: [:edit, :update, :destroy] before_filter :update_order_from_params, only: [:update] before_filter :render_if_save_error, only: [:create, :update] def new; end def edit; end def create redirect_to success_url end def update redirect_to @order end def destroy @order.destroy redirect_to success_url end def load_order @order = Order.find params[:id] end def create_order_from_params @order = Order.new params[:order] end def authorize_user_on_order! permission_denied! unless current_user.can_edit? @order end def update_order_from_params @order.update_attributes end def render_if_save_error unless @order.valid? render error and return false end end
  • 13. class OrderController < ApplicationController before_filter :authenticate_user! def new @order = order end def create @order = refreshed_order @order.save respond_with(@order) end def edit @order = order end def update @order = refreshed_order @order.save respond_with(@order) end def destroy @order = order @order.destroy respond_with(@order) end private def order params[:id] ? ensure_access! Order.find(params[:id]) : Order.new end def resfreshed_order order.tap { |o| o.attributes = params[:order] } end def ensure_access!(order) current_user.can_edit?(order) ? order : permission_denied! endend
  • 14. class OrderController < ApplicationController before_filter :authenticate_user! helper_method :order def new; end def edit; end def create order.save respond_with(order) end def update order.save respond_with(order) end def destroy order.destroy respond_with(order) end private def order @_order ||= refresh(params[:id] ? ensure_access! Order.find(params[:id]) : Order.new) end def resfresh(order) order.tap { |o| o.attributes = params[:order] if params[:order] } end def ensure_access!(order) current_user.can_edit?(order) ? order : permission_denied! endend
  • 15. class OrderController < ApplicationController before_filter :authenticate_user! def new; end def edit; end def create order.save respond_with(order) end def update order.save respond_with(order) end def destroy order.destroy respond_with(order) end expose(:order) { refresh(params[:id] ? ensure_access! Order.find(params[:id]) : Order.new) } private def resfresh(order) order.tap { |o| o.attributes = params[:order] if params[:order] } end def ensure_access!(order) current_user.can_edit?(order) ? order : permission_denied! endend

×