Tag Info

Hot answers tagged

26

When people say "X doesn't compose", what they mean by "compose" really just means "put together", and what and how you put them together can be very different, depending on what exactly "X" is. Also, when they say "doesn't compose", they can mean some slightly different things: You can't put two Xs together at all, period. You can put two Xs together, ...


17

Composability means that you can easily and reliably combine program components together to produce larger components and more complex functionality. Some things that help make components more composable: Idempotence. An idempotent function will always produce the same output or side effects, if called multiple times with the same parameter values. This ...


5

Given a closed set (fixed number of elements) S with elements {a..z} and a binary operator *: There is a single identity element i such that: forall x in S: i * x = x = x * i The operator is associative such that: forall a, b, c in S: a * (b * c) = (a * b) * c You have a monoid. Now given any monoid you can define a binary function f as: f(i, x) = x ...


4

Originally, currying was to simplify analysis, rather than a practical programming technique; in lambda calculus, all functions are unary. Currying is often used at the language level for a similar reason: simplifying the computational model. Partial application is used when a named, useful function can be implemented in terms of another, more general ...


2

Yes it is, because there is no state being mutated. The line branch_counts = [count_leaves(b) for b in tree] can be interpreted as a simple binding (like a let statement in Haskell or Lisp), as there are no further reassignments or mutations. Additionally, you could reformat it like this to make it clearer: def count_leaves(tree): return 1 if ...


2

Your first argument regarding reuse of the HttpClient makes perfect sense. As for the rest of of the requests, I think you're trying to optimize prematurely. That can lead to unnecessary complexity. Also, I'd like to warn you of using the static classes. This is usually a bad idea. It makes your code harder to test and extend. Anyways, below is a design that ...


2

I believe that your question can be rephrased as: why do languages have currying? It is mostly a question of convenience: In Ocaml, you could code let sum3 x y z = x + y + z;; let foo xx yy ll = List.map (sum3 xx yy) ll;; In Scheme you'll need to explicitly make an anonymous function (define (sum3 x y z) (+ x y z)) (define (foo xx yy ll) (map ...


1

import Data.Monoid tryFunctions :: a -> [a -> Maybe b] -> Maybe b tryFunctions x = getFirst . mconcat . map (First . ($ x))


1

bind() doesn't actually do currying. What it does is partial application. lodash and rambda have a method called _.partial() that does partial application without setting the context object. A function f is curried if calling f with one or more arguments is equivalent to calling f with one argument, then calling the return value with the next argument, and ...


1

At it's purest, functional programming is about defining a set of data types, devoid of behaviour, and then defining a set of "free" functions over those data types, which can be freely extended as need arises. This usually comes with some sort of namespace/module mechanism, so despite the fact that the functions are free, they're not global in the sense ...


1

After thinking about it overnight and looking at Nebu's answer, here are the solutions I came up with: Return only the URI, and accept one a/sync Func. While I do think it's reasonable for an API to return the URI to a video (in case the user doesn't want to download it just yet), I think it's a bit technical to ask him/her to download the source of the ...


1

Why not make FromYouTubeAsync be a pure function (e.g. which takes a String representing the HTML of the youtube video page, and which returns the URL of the mp4 video file it finds within), and then have the caller worry about how exactly to download bytes over the internet, if you think they want to have as much control over the process as you're implying? ...



Only top voted, non community-wiki answers of a minimum length are eligible