MARK CHANG'S BLOG

若發生公式跑掉或無法正常顯示的情形,請在公式上按右鍵設定:math setting-> math render->SVG
  • About Me
  • Archive
  • feeds

Posts match “ map ” tag:

almost 9 years ago

Python -- Functional Programming Style 1

今天來看看如何用python的Functional Programming tool來簡化程式碼
所謂的Functional Programming, 是指像是Lisp或Haskell這樣的程式語言
python所提供的Functional Programming tool
可以用Functional Programming這些語言的風格來寫python

Read on →
  • functional_programming
  • map
  • reduce
  • filter
  • March 18, 2014 15:04
  • Permalink
  • Comments
 
over 8 years ago

Ruby -- Enumerable 1 : Collect , Inject

Introduction

在 ruby 裡面, 也有類似 functional programming style 的東西, 像是 map , reduce 之類的

但是這些不是像 python 那樣是屬於 build in function , 像這樣

>>> map(lambda x:x*2 ,[1,2,3,4])
[2, 4, 6, 8]

在 ruby 裡面的 map 是這樣, 如下

irb(main):001:0> [1,2,3,4].map{|x| x*2}
=> [2, 4, 6, 8]

它是 Enumerable Type 的 Method

除此之外, map 和 reduce 在 ruby 裡面還有其他的別名, 就是 collect 和 inject

Read on →
  • ruby
  • enumerable
  • map
  • reduce
  • functional_programming
  • April 30, 2014 23:06
  • Permalink
  • Comments
 

Copyright © 2013 cpmarkchang . Powered by Logdown.
Based on work at subtlepatterns.com.