Advent 2019 part 3, `every-pred` and `some-fn` | xxxAdvent 2019 part 3, `every-pred` and `some-fn` – xxx
菜单

Advent 2019 part 3, `every-pred` and `some-fn`

十一月 30, 2019 - MorningStar

Advent 2019 part 3, `every-pred` and `some-fn`

Posted Tue, 03 Dec 2019 15:07:22

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Ah clojure.core, it’s like an all you can eat hot-pot. Just when you think you’ve scooped up all it has to offer, you discover another small but delicious delicacy floating in the spicy broth.

In exactly the same way I recently became aware of two functions that until now had only existed on the periphery of my awareness. I’ve since enjoyed using them on several occasions, and keep finding uses for them.

These are every-pred, and some-fn. I’ll demonstrate them with an example. Say you have a discussion forum. People can be admins or moderators, and besides their username they can optionally set a nickname.

(def people [{:name   "Elsie"               :admin? true               :mod?   true}              {:name     "Lin Shiwen"               :nickname "Rocky"               :mod?     true}]) 

If you want to grab people’s nickname if they have one, or fall back to their regular name otherwise, then this is pretty elegant with some-fn.

(map (some-fn :nickname :name) people) ;; => ("Elsie" "Rocky") 

If on the other hand you want to find everyone who’s both an admin and a mod, then you can do so easily with every-pred.

(filter (every-pred :admin? :mod?) people) ;; => ({:name "Elsie", :admin? true, :mod? true}) 

Clojure has a bunch of functions with every and some in their names, which can be a bit confusing. In some? and some-> it refers to a value being something other than nil, whereas in some and some-fn it means “the first one that applies”.

I think this overloading is part of the reason why these two have eluded me so long. Only recently did I have the aha insight that while their names are very different they are really each other’s complement. One combines functions with a logical or, the other does so with a logical and.

(map #(or (:nickname %) (:name %)) people) ;; => ("Elsie" "Rocky")  (filter #(and (:admin? %) (:mod? %)) people) ;; => ({:name "Elsie", :admin? true, :mod? true}) 

So next time you find yourself writing an anonymous function like this, consider reaching for some-fn or every-pred instead.

The only difference is that every-pred coerces its result to a boolean, making it a little less general purpose. Say we had an every-fn instead, you could combine it with some to get for instance the name of the first admin in the list.

(some (every-fn :admin? :name) people) 

The implementation of every-fn is left as an exercise to the reader. (hint: it’s just like every-pred, but without the calls to boolean).

Comment on ClojureVerse

More blog posts

Advent 2019 part 24, The Last Post

Posted Tue, 24 Dec 2019 14:52:04

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Day 24, I made it! I did skip a day because I was sick and decided it was more important to rest up, but I’m pretty happy with how far I got.

Let’s see how the others fared who took on the challenge. John Stevenson at Practicalli got four posts out spread out across the advent period, similar to lighting an extra candle every sunday of the advent. Good job!

Advent 2019 part 23, Full size SVG with Reagent

Posted Mon, 23 Dec 2019 20:10:09

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

I’ve been a big fan of SVG since the early 2000’s. To me it’s one of the great victories of web standards. Mind you, browser support has taken a long time to catch up. Back then you had to embed your SVG file with an <object> tag, and support for the many cool features and modules was limited and inconsistent.

These days of course you can drop an <svg> tag straight into your HTML. What a joy! And since the SVG can now go straight into the DOM, you can draw your SVG with React/Reagent. Now there’s a killer combo.

Advent 2019 part 21, Project level Emacs config with .dir-locals.el

Posted Sat, 21 Dec 2019 14:04:39

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

An extremely useful Emacs feature which I learned about much too late is the .dir-locals.el. It allows you to define variables which will then be set whenever you open a file in the directory where .dir-locals.el is located (or any subdirectory thereof).

Here’s an example of a .dir-locals.el file of a project I was poking at today.

Advent 2019 part 20, Life Hacks aka Emacs Ginger Tea

Posted Fri, 20 Dec 2019 14:28:35

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Here’s a great life hack, to peal ginger don’t use a knife, use a spoon. I’m not kidding. Just scrape off the peal with the tip of the spoon, it’s almost too easy.

Here’s a Clojure + Emacs life hack:

Advent 2019 part 19, Advent of Random Hacks

Posted Thu, 19 Dec 2019 19:19:04

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Something I’m pretty good at is coming up with random hacks. The thing where you’re like “hey how about we plug this thing into that thing” and everyone says “why would you do that that’s a terrible idea” and I’m like (mario voice) “let’s a go”.

And sometimes the result is not entirely useless. Like this little oneliner I came up with yesterday, using Babashka to “convert” a project.clj into a deps.edn.

Advent 2019 part 17, trace! and untrace!

Posted Tue, 17 Dec 2019 10:02:59

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Here’s a little REPL helper that you may like.

(defn trace! [v]   (let [m    (meta v)         n    (symbol (str (ns-name (:ns m))) (str (:name m)))         orig (:trace/orig m @v)]     (alter-var-root v (constantly (fn [& args]                                     (prn (cons n args))                                     (apply orig args))))     (alter-meta! v assoc :trace/orig orig)))  (defn untrace! [v]   (when-let [orig (:trace/orig (meta v))]     (alter-var-root v (constantly orig))     (alter-meta! v dissoc :trace/orig))) 

Advent 2019 part 16, Coffee Grinders

Posted Mon, 16 Dec 2019 10:35:27

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Over the last year or so I’ve found myself using some variations on a certain pattern when modelling processes in Clojure. It’s kind of like a event loop, but adapted to the functional, immutable nature of Clojure. For lack of a better name I’m calling these coffee grinders. (The analogy doesn’t even really work but the kid needs to have a name.)

Since I saw Avdi Grimm’s OOPS Keynote at Keep Ruby Weird last year I’ve been thinking a lot about the transaction vs process dichotomy. Avdi talks about the “Transactional Fallacy” from around 15:25. From his slides:

Advent 2019 part 15, jcmd and jstack

Posted Sun, 15 Dec 2019 19:12:50

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Two shell commands anyone using JVM languages should be familiar with are jcmd and jstack. They are probably already available on your system, as they come bundled with the JDK. Try it out, run jcmd in a terminal.

This is what the result might look like

Advent 2019 part 13, Datomic Test Factories

Posted Fri, 13 Dec 2019 09:13:23

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

When I started consulting for Nextjournal I helped them out a lot with tooling and testing. Their data model is fairly complex, which made it hard to do setup in tests. I created a factory based approach for them, which has served the team well ever since.

First some preliminaries. At Nextjournal we’re big fans of Datomic, and so naturally we have a Datomic connection as part of the Integrant system map.

Advent 2019 part 12, Pairing in the Cloud with Tmux

Posted Thu, 12 Dec 2019 11:40:51

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

I’m a strong believer in pair programming. It can be intense and exhausting, and its a skill you need to learn and get good at, but it’s extremely valuable. It improves knowledge sharing, prevents mistakes, and helps people to stay on track to make sure they are building the right thing, which is arguably one of the hardest aspects of our job.

But Gaiwan is a remote-first company. We are spread out across Germany, Brazil, Italy, and work with clients as far away as Singapore and Hong Kong, so we need good ways to pair remotely. For this we need a tool that is

Advent 2019 part 11, Integrant in Practice

Posted Wed, 11 Dec 2019 09:55:25

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

I’ve been a fan of Integrant pretty much ever since it came out. For me there is still nothing that can rival it.

The recently released clip by the folks from Juxt does deserve an honorable mention. It has an interesting alternative approach which some may prefer, but it does not resonate with me. I prefer my system configuration to be just data, rather than code wrapped in data.

Advent 2019 part 10, Hillcharts with Firebase and Shadow-cljs

Posted Tue, 10 Dec 2019 10:43:20

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Recently I led a workshop for a client to help them improve their development process, and we talked a lot about Shape Up, a book released by Basecamp earlier this year that talks about their process. You can read it for free on-line, and I can very much recommend doing so. It’s not a long read and there are a ton of good ideas in there.

One of these ideas has also become a feature in Basecamp, namely hill charts. These provide a great way to communicate what stage a piece of work is in. Are you still going uphill, figuring things out and discovering new work, or are you going downhill, where it’s mostly clear what things will look like, and you’re just executing what you discovered?

Advent 2019 part 9, Dynamic Vars in ClojureScript

Posted Mon, 09 Dec 2019 14:42:00

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Clojure has this great feature called Dynamic Vars, it lets you create variables which can be dynamically bound, rather than lexically. Lexical (from Ancient Greek λέξις (léxis) word) in this case means “according to how it is written”. let bindings for instance are lexical.

(defn hello [x]   (str "hello " x))  (defn greetings []   (str "greetings" foo)) ;; *error*  (let [foo 123]   (hello foo)   (greetings)) 

Advent 2019 part 8, Everything is (not) a pipe

Posted Sun, 08 Dec 2019 13:42:16

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

I’ve always been a big UNIX fan. I can hold my own in a shell script, and I really like the philosophy of simple tools working on a uniform IO abstraction. Uniform abstractions are a huge enabler in heterogenous systems. Just think of Uniform Resource Locators and Identifier (URLs/URIs), one of the cornerstones of the web as we know it.

Unfortunately since coming to Clojure I feel like I’ve lost of some of that power. I’m usually developing against a Clojure process running inside (or at least connected to) my trusty editor, and the terminal plays second fiddle. How do I pipe things into or out of that?

Advent 2019 part 7, Do that doto

Posted Sat, 07 Dec 2019 19:43:35

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

doto is a bit of an oddball in the Clojure repertoire, because Clojure is a functional language that emphasizes pure functions and immutabilty, and doto only makes sense when dealing with side effects.

To recap, doto takes a value and a number of function or method call forms. It executes each form, passing the value in as the first argument. At the end of the ride it returns the original value.

Advent 2019 part 6, A small idiom

Posted Fri, 06 Dec 2019 12:09:03

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

As an avid tea drinker I’ve been poring (pouring?) over this catalog of teas.

(def teas [{:name "Dongding"             :type :oolong}            {:name "Longjing"             :type :green}            {:name "Baozhong"             :type :oolong}            {:name "Taiwan no. 18"             :type :black}            {:name "Dayuling"             :type :oolong}            {:name "Biluochun"             :type :green}]) 

Advent 2019 part 5, Clojure in the shell

Posted Thu, 05 Dec 2019 16:57:16

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

I already showed you netcat, and how it combines perfectly with socket REPLs. But what if all you have is an nREPL connection? Then you use rep

$ rep '(clojure.tools.namespace.repl/refresh)' :reloading () :ok 

Advent 2019 part 4, A useful idiom

Posted Wed, 04 Dec 2019 15:47:39

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Here’s a little Clojure idiom that never fails to bring me joy.

(into {} (map (juxt key val)) m) 

Advent 2019 part 2, Piping hot network sockets with Netcat

Posted Mon, 02 Dec 2019 15:09:05

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

Part of what I want to do in this series is simply point at some of the useful tools and libraries I discovered in the past year. I’ve adopted a few tools for doing network stuff on the command line which I’ll show you in another post. First though we’ll look at a classic: netcat!

I’ve been using netcat for years, it’s such a great tool. It simply sets up a TCP connection and connects it to STDIN/STDOUT. Pretty straightforward. I’ve been using it more and more though because of Clojure’s socket REPL.

Advent 2019 part 1, Clojure Vocab: to Reify

Posted Sun, 01 Dec 2019 21:46:44

This post is part of Advent of Parens 2019, my attempt to publish one blog post a day during the 24 days of the advent.

An interesting aspect of the Clojure community, for better or for worse, is that it forms a kind of linguistic bubble. We use certain words that aren’t particularly common in daily speech, like “accretion”, or use innocuous little words to refer to something very specific. Even a simple word like “simple” is no longer that simple.

We can thank Rich Hickey for this. He seems to care a great deal about language, and is very careful in picking the words he uses in his code, documentation, and in his talks.

Advent of Parens 2019

Posted Mon, 25 Nov 2019 19:14:00

Ah, the advent, the four weeks leading up to Christmas. That period of glühwein and office year-end parties.

The last couple of years I’ve taken part in the Advent of Code, a series of programming puzzles posted daily. They’re generally fun to do and wrapped in a nice narrative. They also as the days progress start taking up way too much of my time, so this year I won’t be partaking in Advent of Code, instead I’m trying something new.

From the first to the 24th of December I challenge myself to write a single small blog post every day. If my friend Sarah Mirk can do a daily zine for a whole year, surely I can muster a few daily paragraphs for four weeks.

Fork This Conference

Posted Fri, 09 Aug 2019 11:16:43

Last weekend Heart of Clojure took place in Leuven, Belgium. As one of the core organizers it was extremely gratifying to see this event come to life. We started with a vision of a particular type of event we wanted to create, and I feel like we delivered on all fronts.

For an impression of what it was like you can check out Malwine’s comic summary, or Manuel’s blog post.

It seems people had a good time, and a lot of people are already asking about the next edition. However we don’t intend to make this a yearly recurring conference. We might be back in two years, maybe with another Heart of Clojure, maybe with something else. We need to think about that.

Advice to My Younger Self

Posted Wed, 07 Aug 2019 13:43:58

When I was 16 I was visited by a man who said he had come from the future. He had traveled twenty years back to 1999 to sit down with me and have a chat.

We talked for an hour or so, and in the end he gave me a few pieces of advice. I have lived by these and they have served me well, and now I dispense this advice to you.

Become allergic to The Churn

ClojureScript logging with goog.log

Posted Mon, 10 Jun 2019 16:02:09

This post explores goog.log, and builds an idiomatic ClojureScript wrapper, with support for cljs-devtools, cross-platform logging (by being API-compatible with Pedestal Log), and logging in production.

This deep dive into GCL’s logging functionality was inspired by work done with Nextjournal, whose support greatly helped in putting this library together.

Clojure’s standard library isn’t as “batteries included” as, say, Python. This is because Clojure and ClojureScript are hosted languages. They rely on a host platform to provide the lower level runtime functionality, which also allows them to tap into the host language’s standard library and ecosystem. That’s your batteries right there.

The Art of Tree Shaping with Clojure Zippers

Posted Mon, 26 Nov 2018 14:48:06

This is a talk I did for the “Den of Clojure” meetup in Denver, Colorado. Enjoy!

Captions (subtitles) are available, and you can find the transcript below, as well as slides over here.

For comments and discussion please refer to this post on r/Clojure.

Test Wars: A New Hope

Posted Fri, 02 Nov 2018 16:51:58

Yesterday was the first day for me on a new job, thanks to Clojurists Together I will be able to dedicate the coming three months to improving Kaocha, a next generation test runner for Clojure.

A number of projects applied for grants this quarter, some much more established than Kaocha. Clojurists Together has been asking people through their surveys if it would be cool to also fund “speculative” projects, and it seems people agreed.

I am extremely grateful for this opportunity. I hope to demonstrate in the coming months that Kaocha holds a lot of potential, and to deliver some of that potential in the form of a tool people love to use.

Two Years of Lambda Island, A Healthy Pace and Things to Come

Posted Fri, 15 Jun 2018 12:15:02

It’s been just over two years since Lambda Island first launched, and just like last year I’d like to give you all an update about what’s been happening, where we are, and where things are going.

To recap: the first year was rough. I’d been self-employed for nearly a decade, but I’d always done stable contracting work, which provided a steady stream of income, and made it easy for me to unplug at the end of the day.

Lambda Island was, as the Dutch expression goes, “a different pair of sleeves”. I really underestimated what switching to a one-man product business in a niche market would mean, and within months I was struggling with symptoms of burnout, so most of year one was characterised by trying to keep things going and stay afloat financially, while looking after myself and trying to get back to a good place, physically and mentally.

D3 and ClojureScript

Posted Thu, 26 Apr 2018 09:00:00

This is a guest post by Joanne Cheng (twitter), a freelance software engineer and visualization consultant based in Denver, Colorado. She has taught workshops and spoken at conferences about visualizing data with D3. Turns out ClojureScript and D3 are a great fit, in this post she’ll show you how to create your own visualization using the power of D3 and the elegance of ClojureScript.

I use D3.js for drawing custom data visualizations. I love using the library, but I wanted to try one of the several compile to JavaScript options, and I decided to look into ClojureScript. It ended up working out well for me, so I’m going to show you how I created a D3.js visualization using ClojureScript!

What we’re visualizing

Reloading Woes

Posted Fri, 09 Feb 2018 06:48:13

Setting the Stage

When doing client work I put a lot of emphasis on tooling and workflow. By coaching people on their workflow, and by making sure the tooling is there to support it, a team can become many times more effective and productive.

An important part of that is having a good story for code reloading. Real world projects tend to have many dependencies and a large amount of code, making them slow to boot up, so we want to avoid having to restart the process.

The Bare Minimum, or Making Mayonnaise with Clojure

Posted Fri, 29 Dec 2017 14:38:24

Making Mayonnaise

Imagine you have a grandfather who’s great at making mayonnaise. He’s been making mayonnaise since before the war, and the result is truly excellent. What’s more, he does this with a good old fashioned whisk. He’s kept his right arm in shape throughout decades just by beating those eggs and oil and vinegar.

Now he’s bought himself a handheld electric mixer after hearing his friend rave about hers, but after a few tries he gives up and goes back to his whisk. He says he just can’t get the same result. This seems slightly odd, so the next time you go over you ask him to show you how he uses the mixer.

Clojure Gotchas: “contains?” and Associative Collections

Posted Mon, 02 Oct 2017 16:01:45

When learning a programming language we rarely read the reference documentation front to back. Instead someone might follow some tutorials, and look at sample code, until they’re confident enough to start a little project for practice.

From that point on the learning process is largely “just in time”, looking up exactly the things you need to perform the task at hand. As this goes on you might start to recognize some patterns, some internal logic that allows you to “intuit” how one part of the language works, based on experience with another part.

Developing this “intuition” — understanding this internal logic — is key to using a language effectively, but occasionally our intuition will be off. Some things are simply not obvious, unless someone has explained them to us. In this post I will look at something that frequently trips people up, and attempt to explain the underlying reasoning.

Dates in Clojure: Making Sense of the Mess

Posted Wed, 26 Jul 2017 10:53:12

Update 2018-11-27: while most of this article is still relevant, I no longer recommend using JodaTime as the main date/time representation for new projects. Even existing projects that aren’t too invested in JodaTime/clj-time should consider migrating to java.time and clojure.java-time across the board.

Update 2 2019-05-29: Also check out the talk Cross Platform DateTime Awesomeness by Henry Widd, given at Clojure/north 2019

You can always count on human culture to make programming messy. To find out if a person is a programmer just have them say “encodings” or “timezones” and watch their face.

Clojure Gotchas: Surrogate Pairs

Posted Mon, 12 Jun 2017 19:12:17

tl;dr: both Java and JavaScript have trouble dealing with unicode characters from Supplementary Planes, like emoji 😱💣.

Today I started working on the next feature of lambdaisland/uri, URI normalization. I worked test-first, you’ll get to see how that went in the next Lambda Island episode.

One of the design goals for this library is to have 100% parity between Clojure and ClojureScript. Learn once, use anywhere. The code is all written in .cljc files, so it can be treated as either Clojure or ClojureScript. Only where necessary am I using a small amount of reader conditionals.

Simple and Happy; is Clojure dying, and what has Ruby got to do with it?

Posted Thu, 25 May 2017 13:55:39

The past week or so a lot of discussion and introspection has been happening in the Clojure community. Eric Normand responded to my one year Lambda Island post with some reflections on the size and growth of the community.

And then Zack Maril lamented on Twitter: “I’m calling it, clojure’s dying more than it is growing”. This sparked a mega-thread, which was still raging four days later. A parallel discussion thread formed on Reddit. Someone asked if their were any Clojure failure stories. They were pointed at this talk from RubyConf 2016, which seemed to hit a lot of people right in the feels, and sparked a subthread with a life of its own.

Meanwhile Ray, one of the hosts of the defn podcast reacted to the original tweet: “I’m calling it: Clojure is alive and well with excellent defaults for productive and sustainable software development.” This sparked another big thread.

Loading Clojure Libraries Directly From Github

Posted Wed, 17 May 2017 13:58:50

Did you ever fix a bug in an open source library, and then had to wait until the maintainer released an updated version?

It’s happened to me many times, the latest one being Toucan. I had run into a limitation, and found out that there was already an open ticket. It wasn’t a big change so I decided to dive in and address it. Just a little yak shave so I could get on with my life.

Now this pull request needs to be reviewed, and merged, and eventually be released to Clojars, but ain’t nobody got time for that stuff. No sir-ee.

Lambda Island Turns One, The Story of a Rocky Ride

Posted Sat, 13 May 2017 11:14:34

One year ago to date I launched Lambda Island, a service that offers high quality video tutorials on web development with Clojure and ClojureScript. It’s been quite a ride. In this post I want to look back at the past year, provide some insight into how this experience has been for me, and give you a glimpse of what the future has in store.

This story really starts in December 2015. After three years of doing contract work for Ticketsolve I decided it was time for a change. I have been self-employed for many years, but I knew that sooner or later I wanted to try my hand at selling a product, rather than selling my time.

In January and February I took some time for soul-searching, and recharging. I went to speak at RubyConf Australia, and got to hang out with some old friends around Australia and New Zealand. Once back in Berlin I got busy creating Lambda Island.

Writing Node.js scripts with ClojureScript

Posted Tue, 02 May 2017 16:49:32

In the two most recent  Lambda Island episodes I covered in-depth how to create command line utilities based on Lumo, how to combine them with third party libraries, and how to deploy them to npmjs.com.

However there’s a different way to create tools with ClojureScript and distribute them through NPM, without relying on Lumo. In this blog post I want to quickly demostrate how to do just that.

To recap, Lumo is a ClojureScript environment based on Node.js, using bootstrapped (self-hosted) ClojureScript. This means the ClojureScript compiler, which is written in Clojure and runs on the JVM, is used to compile itself to JavaScript. This way the JVM is no longer needed, all you need is a JavaScript runtime to compile and run ClojureScript code, which in this case is provided by Node.js. On top of that Lumo uses nexe, so Lumo can be distributed as a single compact and fast executable binary.

Announcing lambdaisland/uri 1.0.0

Posted Mon, 27 Feb 2017 08:35:05

I just released lambdaisland/uri, a pure Clojure/ClojureScript URI library. It is available on Github and Clojars.

This is a small piece of the code base that powers lambdaisland.com. It’s inspired by Ruby’s Addressable::URI, the most solid URI implementation I’ve seen to date, although it only offers a small part of the functionality that library offers.

It’s written in pure Clojure/ClojureScript, with only minimal use of .cljc reader conditionals to smooth over differences in regular expression syntax, and differences in core protocols. It does not rely on any URI functionality offered by the host, such as java.net.URL, so it’s usable across all current and future Clojure implementations (Clojure, ClojureScript, ClojureCLR).

re-frame Subscriptions Got Even Better

Posted Sat, 11 Feb 2017 11:10:43

Up until recently, to use re-frame subscriptions in Reagent views, you had to use a form-2 component.

A form-2 component is a function that returns another function, which does the actual rendering of the component to hiccup. In contrast, a form-1 component renders the hiccup directly.

(map (some-fn :nickname :name) people) ;; => ("Elsie" "Rocky") 

0

Game Development with Clojure/ClojureScript

Posted Thu, 08 Dec 2016 21:19:22

This weekend it’s Ludum Dare again, the world’s longest running game jam. The idea is that, alone or with a team, you build a game in a weekend based on a certain theme.

We got a little team together here in Berlin, and so I’ve been reviewing what options there are for someone wanting to build a game in Clojure or Clojurescript.

The good news is there are plenty of options, as you’ll see from the list below. You can do desktop games, browser based games with canvas or webgl, and you can even create Unity 3D games, all from your comfortable Clojure parentheses.

Union Types with Clojure.Spec

Posted Sun, 25 Sep 2016 17:04:50

Elm and other statically typed languages have a great feature called Union Types (also called Sum Types or Algebraic Data Types).

Here’s an example taken from Elm. Suppose your system used to represent users as integers, maybe just an auto-incrementing primary key, but then switched to UUIDs represented as strings.

To correctly model this situation, you need a way to create a type that can be either an integer or a string, that’s what union types give you.

Become a Clojure Pro

11 hours 6 minutes and 40 seconds of Premium Video Content

In-depth tutorials
Backend, frontend, language and tooling
Complete transcripts and source code

Start your free trial today!

Advent 2019 part 3, `every-pred` and `some-fn`


Notice: Undefined variable: canUpdate in /var/www/html/wordpress/wp-content/plugins/wp-autopost-pro/wp-autopost-function.php on line 51