I think the F # pipe ( |> ) operator should be against ( & ) in haskell.
// pipe operator example in haskell factorial :: (Eq a, Num a) => a -> a factorial x = case x of 1 -> 1 _ -> x * factorial (x-1)
// terminal ghic >> 5 & factorial & show
If you don't like the ( & ) operator, you can configure it as F # or Elixir:
(|>) :: a -> (a -> b) -> b (|>) xf = fx infixl 1 |>
ghci>> 5 |> factorial |> show
Why infixl 1 |> ? See the document in Data-Function (&)
infixl = infix + left associativity
infixr = infix + right associativity
(.)
( . ) means the composition of the function. This means (fg) (x) = f (g (x)) in mathematics.
foo = negate . (*3)
// ouput -3 ghci>> foo 1 // ouput -15 ghci>> foo 5
it is equal
// (1) foo x = negate (x * 3)
or
// (2) foo x = negate $ x * 3
The ( $ ) operator is also defined in Data-Function ($) .
( . ) is used to create a Hight Order Function or closure in js . See an example:
// (1) use lamda expression to create a Hight Order Function ghci> map (\x -> negate (abs x)) [5,-3,-6,7,-3,2,-19,24] [-5,-3,-6,-7,-3,-2,-19,-24] // (2) use . operator to create a Hight Order Function ghci> map (negate . abs) [5,-3,-6,7,-3,2,-19,24] [-5,-3,-6,-7,-3,-2,-19,-24]
Wow, Less is (code) is better.
Compare |> and .
ghci> 5 |> factorial |> show // equals ghci> (show . factorial) 5 // equals ghci> show . factorial $ 5
Differences between left —> right and right —> left . ⊙﹏⊙ |||
humanization
|> and & better than .
as
ghci> sum (replicate 5 (max 6.7 8.9)) // equals ghci> 8.9 & max 6.7 & replicate 5 & sum // equals ghci> 8.9 |> max 6.7 |> replicate 5 |> sum // equals ghci> (sum . replicate 5 . max 6.7) 8.9 // equals ghci> sum . replicate 5 . max 6.7 $ 8.9
How to make functional programming in an object-oriented language?
please visit http://reactivex.io/
IT support:
- Java: RxJava
- JavaScript: RxJS
- C #: Rx.NET
- C # (Unity): UniRx
- Scala: RxScala
- Clojure: RxClojure
- C ++: RxCpp
- Lua: RxLua
- Ruby: Rx.rb
- Python: RxPY
- Go: RxGo
- Groovy: RxGroovy
- JRuby: RxJRuby
- Kotlin: RxKotlin
- Swift: RxSwift
- PHP: RxPHP
- Elixir: Reactive
- Dart: RxDart