Skip to content

blackwood/vervel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vervel

Build Status Delicious

vervel is an experiment in creating a functional utility library for PHP modeled as much as possible after Clojure's core library. thus its goal is to mock as many of Clojure's standard functions through aliasing, reordering of arities, or writing an implementation of the function. vervel is not currently a library which intends to bring any new data types or drastically different functionality to PHP itself, so if you're looking for laziness, persistent data structures or concurrency, maybe check back in a decade or so...

use in production at your own risk!

vervel lib

As a general rule, functions will be identical to their name in Clojure except converted from kebab-case to snake_case and have their ? stripped (illegal character in PHP) unless that function name (after aforementioned conversion) already exists in PHP. Still figuring out a naming strategy that will be straightforward for that case. Consider the following:

The function empty in Clojure returns an empty colleciton or nil, while Clojure's empty? is used to check if a collection has no items. PHP already implements empty to check if an array is empty--and regardless, since PHP doesn't allow ?, we'd still have ended up with two identically named functions if we tried to implement both. Since modifying core functions is a no-no, a new version of Clojure's empty will require a different name. Suggestions for strategy here is welcome.

Also, some functions, such as array_map,array_reduce and array_filter have had their arities made consistent and the prefix array_ stripped (to reduce noise).

support

As previously mentioned, full support of Clojure's data types is not the end goal, so many core Clojure functions are not here. This is more a wishlist/to-do list of planned support. If you can make a good argument for a function I missed, I'll try to support it!

key

Supported - ✅
Planned Support - ⬜
Won't Support - ❌

flow control

fn support
not
and ❌ (unless namespace conflict can be resolved)
or ❌ (unless namespace conflict can be resolved)
cond ❌ (covered by switch case, more or less.)

arrays (collections)

fn support
count ❌ (exists in PHP)
empty ❌ (unless namespace conflict can be resolved)
not-empty ❌ (unless namespace conflict can be resolved)
into ❌ (types not applicable)
conj
cons
contains? ✅ (see contains)
distinct?
empty? ❌ (exists in PHP)
every? ✅ (see every)
not-every? ✅ (see not_every)
some
not-any? ✅ (see not_any)
get
assoc
dissoc
merge ⬜ (will alias array_merge and make non-destructive)
merge-with
first
last
rest
butlast
map
filter
reduce ✅ (note: arity of 'initial' arg preserved)
remove
concat
reverse ✅ (alias of array_reverse)
interleave ✅ (alias of implode, not lazy)
interpose ✅ (not lazy)
zipmap ⬜ (will alias array_combine)
frequencies ⬜ (will alias array_count_values)
select-keys ✅ (see select_keys)
keys ⬜ (will alias array_keys)
vals ⬜ (will alias array_values)
find ⬜ (maybe, could be duplicative of get)
update-in
seq ⬜ (could be useful for nil punning, maybe not)
rand-nth
second
take ⬜ (not lazy)
take-last ⬜ (not lazy)
take-nth ⬜ (not lazy)
take-while ⬜ (not lazy)
drop ⬜ (not lazy)
drop-last ⬜ (not lazy)
drop-while ⬜ (not lazy)
keep ⬜ (not lazy)
keep-indexed ⬜ (not lazy)
distinct ⬜ (will alias array_unique, not lazy)
group-by
partition ⬜ (not lazy)
partition-all ⬜ (not lazy)
partition-by
split-at
split-with
replace
shuffle ❌ (shuffle exists, may provide another version?)
reductions
mapcat
max-key
min-key

numbers

fn support
pos?
zero?
neg?
identical? ⬜ (undecided)
nil? ⬜ (could be equivalent to is_null)
even? ✅ (see even)
odd? ✅ (see odd)
max ❌ (exists in PHP)
min ❌ (exists in PHP)
quot
rem
mod (will alias % operator)
inc
dec
max ❌ (exists in PHP)
min ❌ (exists in PHP)

functions

fn support
complement
comp
juxt
apply ✅ (alias of call_user_func_array)

About

vervel is a set of functional PHP utility methods inspired by Clojure and other functional langs/libs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages