abstraction

How to let a function [a] -> [a] operate on [(a,Int)]?

我们两清 提交于 2019-12-05 02:22:50
I find myself often writing code following the pattern: foo xs = map snd $ filter ((< 10).fst) $ zip xs [0..] bar ys = map snd $ sortBy (compare `on` fst) $ zip ys [0..] Now I want to abstract this away foo = indexesOf (filter (<10)) bar = indexesOf sort indexesOf :: ([a] -> [a]) -> [a] -> [Int] indexesOf f xs = map snd $ magick $ zip xs [0..] where magick = undefined How to perform the magick ? Your type signature won't work. You need to be able to give the passed function a list of tuples, which means that you either have to use higher-rank types to force it to be polymorphic, or explicitly

How many levels of abstraction do I need in the data persistence layer?

∥☆過路亽.° 提交于 2019-12-05 02:06:47
问题 I'm writing an application using DDD techniques. This is my first attempt at a DDD project. It is also my first greenfield project and I am the sole developer. I've fleshed out the domain model and User interface. Now I'm starting on the persistence layer. I start with a unit test, as usual. [Test] public void ShouldAddEmployerToCollection() { var employerRepository = new EmployerRepository(); var employer = _mockery.NewMock<Employer>(); employerRepository.Add(employer); _mockery

Enum abstraction problem

谁说胖子不能爱 提交于 2019-12-04 18:25:13
I am currently struggling with a java abstraction problem. I have something like this: public interface State { }; public interface Dynamics { getObservationChance(State state, Observation observation); }; class SpecialState implements State { }; enum SpecialObservation() { FREE, WALL, etc. } class SpecialDynamics implements Dynamics { getObservationChance(State state, Observation observation) { // state should be SpecialState, observation should be SpecialObservation! } }; class Main { Main(State state, Observation observation, Dynamics dynamics) { dynamics.getObservationChance(state,

Mysqli abstraction, fetching arrays from prepared statements

时光怂恿深爱的人放手 提交于 2019-12-04 16:50:30
Lately I've stumbled upon an error in a lib that used to work just fine, and I'll be damned if I can figure out where it is. The code sample is below, and I apologize for the debug stuff that's inside it, but I'm trying to get it to work. The problem is that $temp is an array with correct key (the name of the columns) but all the values are NULL. I think the problem lies in the call_user_func_array(array($query, 'bind_result'), $params); bit, but can't really wrap my head around it. public function fetchRows(){ error_reporting(E_ALL+E_NOTICE); $args = func_get_args(); $sql = array_shift($args)

Exceptions and Abstractions

不打扰是莪最后的温柔 提交于 2019-12-04 12:26:05
When should you throw a custom exception? e.g. I have some code that connects to a server. The code that connects to the server throws an IOException when it fails to connect. In the context of the method it's called, this is fine. It's also fine in the network code. But as this represents not having a connection (and therefore not working) the exception goes all the way up to the ui. At this stage, an IOException is very ambigous. Something like NoConnectionException would be better. So, my question is: At what stage should you catch an exception to instead throw another (custom) exception

What does “data abstraction” exactly mean?

隐身守侯 提交于 2019-12-04 08:29:56
问题 What does data abstraction refer to? Please provide real life examples alongwith. 回答1: Abstraction has two parts: Hide details that don't matter from a certain point of view Identify details that do matter from a certain point of view and consider items to be of the the same class if they possess those details. For example, if I am designing a program to deal with inventory, I would like to be able to find out how many items of a certain type the system has in stock. From the perspective of

Design(How-to) of classes containing collections of other classes

三世轮回 提交于 2019-12-04 07:04:51
How to design classes involving collections of other classes? General Example: A Workspace contains number of Projects . A Project contains large number of Resources . Each Resource may contain large number of Files . So here the classes identified can be Workspace,Project,Resource and File. Workspace will have list of Project.Project will have list of Resources and Resource will have list of Files. Of course each class has its related settings. Now the basic questions are : a) Who creates and adds a class to a particular collection? Another class or the class containing the collection? b)

Sharing functions between namespaces in Clojure

淺唱寂寞╮ 提交于 2019-12-04 03:02:17
I may very well be approaching this in the wrong way, so please forgive me of my naiveté: In order to learn Clojure I've begun porting my OAuth client library for Python to Clojure. I'm doing this by wrapping clj-http much in the same way I wrap Python Requests in the Python library. This seems to be working pretty well so far and I'm really enjoying seeing the implementation come to life in Clojure. However I have run into a problem: I'm planning to support both OAuth 1.0 and 2.0 and have split the respective functions into two files: oauth1.clj and oauth2.clj. Now, each file should ideally

How to get the name of the calling class (in PHP)

被刻印的时光 ゝ 提交于 2019-12-03 15:04:53
问题 define('anActionType', 1); $actionTypes = array(anActionType => 'anActionType'); class core { public $callbacks = array(); public $plugins = array(); public function __construct() { $this->plugins[] = new admin(); $this->plugins[] = new client(); } } abstract class plugin { public function registerCallback($callbackMethod, $onAction) { if (!isset($this->callbacks[$onAction])) $this->callbacks[$onAction] = array(); global $actionTypes; echo "Calling $callbackMethod in $callbacksClass because

Access Control List (ACL) abstraction layer in .net

雨燕双飞 提交于 2019-12-03 13:23:09
问题 Is there an ACL abstraction layer available in .net? I have seen some "best practices" documents but no good base implementation. What about the System.Security.AccessControl? Is this a good starting point? The ACL's should work with Roles stored in DB as well as Roles by the system and for in-memory-object definitions as well as db objects or files. So it should be generic and/or easy to extend. Should this rely on IPrincipal, IIdentity from the .net framework? Zend has something similar in